package com.ruoyi.surfacewater.service.impl;

import com.ruoyi.base.domain.BussinessItemVo;
import com.ruoyi.base.mapper.PublicToolsMapper;
import com.ruoyi.base.service.PublicToolsService;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.core.page.PageDomain;
import com.ruoyi.common.core.page.TableSupport;
import com.ruoyi.common.utils.*;
import com.ruoyi.common.utils.excel.ExcelUtiles;
import com.ruoyi.common.utils.js.ItemCodeOverData;
import com.ruoyi.common.utils.js.Standard;
import com.ruoyi.common.utils.js.WaterLevelCompute;
import com.ruoyi.drinkwater.domain.ManualParamVo;
import com.ruoyi.drinkwater.mapper.BaseDrinkSegmentMapper;
import com.ruoyi.drinkwater.mapper.WqDataTempdataMapper;
import com.ruoyi.monitor.domain.BusWaterIntegrationmonitordata;
import com.ruoyi.surfacewater.domain.*;
import com.ruoyi.surfacewater.mapper.*;
import com.ruoyi.surfacewater.service.BusMonthlycumulativedataService;
import com.ruoyi.surfacewater.service.ManualDataService;
import com.ruoyi.system.domain.SysConfig;
import com.ruoyi.system.mapper.SysConfigMapper;
import com.ruoyi.utli.SegmentFormula;
import org.apache.commons.io.FilenameUtils;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;

@Service
public class ManualDataServiceImpl implements ManualDataService {
    @Autowired
    private ManualDataMapper manualMonitorDataMapper;
    @Autowired
    private PublicToolsMapper publicToolsMapper;
    @Autowired
    private SysConfigMapper sysConfigMapper;
    @Autowired
    private RuoYiConfig ruoYiConfig;
    @Autowired
    private PublicToolsService publicToolsService;
    @Autowired
    private BusBasicsmonitordataMapper busBasicsmonitordataMapper;

    @Autowired
    private BusBasicevaluatedataMapper busBasicevaluatedataMapper;

    @Autowired
    private SegmentFormula segmentFormula;
    @Autowired
    private BusIntegrationmonitordataMapper busIntegrationmonitordataMapper;
    @Autowired
    private BusIntegrationevaluatedataMapper busIntegrationevaluatedataMapper;

    @Autowired
    private BusMonthlycumulativedataService busMonthlycumulativedataService;
    @Autowired
    private WqDataTempdataMapper wqDataTempdataMapper;

    @Autowired
    private BaseDrinkSegmentMapper baseDrinkSegmentMapper;

    @Override
    public List<Map<String, Object>> manualMonitorData(ManualDataVo vo) {


        List<Map<String, Object>> listdata = new ArrayList<>();
        DecimalFormat df = new DecimalFormat("#.0000");

        DecimalFormat dfql = new DecimalFormat("###.###");
        if (!StringUtils.isNotEmpty(vo.getBussinessCategoryCode())) {
            vo.setBussinessCategoryCode("CBN");
        }
        if (StringUtils.isNotEmpty(vo.getSegmentId())) {
            vo.setSegmentIdList(Arrays.asList(vo.getSegmentId().split(",")));
        }
        if (StringUtils.isNotEmpty(vo.getItemCode())) {
            vo.setItemCodeList(Arrays.asList(vo.getItemCode().split(",")));
        }
        if (StringUtils.isNotEmpty(vo.getBeginTime())) {
            vo.setBeginTime(vo.getBeginTime() + "-01");
        }
        if (StringUtils.isNotEmpty(vo.getEndTime())) {
            vo.setEndTime(DateUtils.getYearMonthLastDay(vo.getEndTime()));
        }
        if (StringUtils.isNotEmpty(vo.getIsOver()) && !"1".equals(vo.getIsOver())) {
            vo.setIsOver(null);
        }
        //查询出监测时间
        List<Map<String, Object>> manualList = manualMonitorDataMapper.manualMonitordataLastTime(vo);
        //查询监测值数据
        List<Map<String, Object>> manualListData = manualMonitorDataMapper.manualMonitordataList(vo);

        BussinessItemVo itemVo = new BussinessItemVo();
        itemVo.setBussinessCategoryCode("CBN");
        List<Map<String, Object>> itemList = publicToolsService.bussinessItemData(itemVo);

        //查询标准值
        Map<String, Object> standardcategoryMap = new HashMap<>();
        standardcategoryMap.put("waterBody", "1");
        List<Map<String, Object>> wqBasStandardcategorylist = publicToolsMapper.busStandardcategorylist(standardcategoryMap);

        //源对象条件判断属性名 断面id
        String srcEqualProp = "SegmentID";
        //源对象待设置属性名   断面时间
        String srcSetProp = "SampleDate";
        String dataSource = "dataSource";
        /*因子id加 _Val 是监测因子数据
        因子id加 _OverTimes 是超标倍数
        因子id加 _IsOver 是否超标 0正常 1超标*/
        long t1 = System.currentTimeMillis();
        //使用Java8自带的stream特性进行转换行转列
        List<Map<String, Object>> resultList = manualList.stream().map(m1 -> {
            //超标描述
            List<Map<String, Object>> overStandardFactors = new ArrayList<>();
            String overMessage = "";
            manualListData.stream()  //获取监测值的数据
                    .filter(m2 -> Objects.equals(m2.get(srcEqualProp), m1.get(srcEqualProp)) && Objects.equals(m2.get(srcSetProp), m1.get(srcSetProp)) && Objects.equals(m2.get(dataSource), m1.get(dataSource)))
                    .forEach(m2 -> {
                        //分组i
                        Object itemCode = m2.get("ItemCode");
                        Object itemName = m2.get("ItemName");
                        Object TargetLevel = m2.get("TargetLevel");
                        Object Unit = m2.get("Unit");
                        Object SegmentCategory = m2.get("SegmentCategory");
                        List<Map<String, Object>> sunmapsWaterTypelist = new ArrayList<>();
                        if (wqBasStandardcategorylist != null && wqBasStandardcategorylist.size() > 0) {
                            //使用Java8自带的stream特性进行转换行转列
                            // 使用filter()方法根据条件过滤元素
                            sunmapsWaterTypelist = wqBasStandardcategorylist.stream()
                                    .filter(wqBasStandardcategorylistmap -> String.valueOf(wqBasStandardcategorylistmap.get("itemCode")).equals(String.valueOf(itemCode)) && String.valueOf(wqBasStandardcategorylistmap.get("level")).equals(String.valueOf(TargetLevel)) && String.valueOf(wqBasStandardcategorylistmap.get("waterType")).equals(String.valueOf(SegmentCategory)))   // 只保留能被2整除的元素
                                    .collect(Collectors.toList());
                        }
                        //
                        List<Map<String, Object>> itemEvaluteList = itemList.stream().filter(s -> String.valueOf(s.get("itemCode")).equals(String.valueOf(itemCode))).collect(Collectors.toList());

                        int ieke = 0;
                        if (sunmapsWaterTypelist != null && sunmapsWaterTypelist.size() > 0) {
                            Object standardValue = sunmapsWaterTypelist.get(0).get("standardValue");
                            m1.put(m2.get("ItemCode") + "_standardValue", standardValue);//监测因子对应值
                            if (standardValue != null && !"".equals(standardValue)) {
                                String valueAsString = String.valueOf(standardValue);
                                if (valueAsString.indexOf('.') < 0) {
                                    // 没有小数点，即整数或零小数位
                                    //return 0;
                                }

                                ieke = valueAsString.length() - valueAsString.indexOf('.');
                            }
                        }

                        if ("15DE941F-A221-4D9C-8387-48B0E99F6E25".equals(String.valueOf(m2.get("ItemCode")).toUpperCase())) {
                            m1.put(m2.get("ItemCode") + "_standardValue", "6~9");//监测因子对应值

                        }
                        m1.put(m2.get("ItemCode") + "_unit", Unit);
                        Object keepPointBits = m2.get("KeepPointBits");
                        if (keepPointBits != null && !"".equals(keepPointBits)) {
                            ieke = Integer.valueOf(String.valueOf(keepPointBits));
                        }
                        Object effectiveValue = m2.get("EffectiveValue");

                        if (effectiveValue != null && !"".equals(effectiveValue)) {
                            Double aDouble = Double.valueOf(String.valueOf(effectiveValue));
                            BigDecimal bd = new BigDecimal(String.valueOf(aDouble));
                            String s = BankerSRoundingUtils.sciCal(aDouble, ieke);
                            bd = new BigDecimal(s);
                            if (bd.signum() != 0) {
                                m1.put(m2.get("ItemCode") + "_Val", String.valueOf(bd));//监测因子对应值
                            } else {
                                //处理数据不能为0
                                String effectiveValuesdata = null;
                                Double aDouble1 = SegmentFormula.ConvertData(aDouble);
                                //判断是否科学计算法，如果是就进行转换
                                boolean scientificNotation = StringUtils.isScientificNotation(String.valueOf(aDouble1));
                                if (scientificNotation) {
                                    BigDecimal bigDecimal = new BigDecimal(String.valueOf(aDouble1));
                                    String effectiveValuesdatas = bigDecimal.toPlainString();
                                    effectiveValuesdata = effectiveValuesdatas;
                                } else {
                                    if (aDouble1 != null && !"--".equals(aDouble1) && !"-1".equals(aDouble1) && !"*".equals(aDouble1) && !"".equals(aDouble1)) {
                                        effectiveValuesdata = String.valueOf(aDouble1);
                                    }
                                }
                                m1.put(m2.get("ItemCode") + "_Val", effectiveValuesdata);//监测因子对应值
                            }


                            m1.put(m2.get("ItemCode") + "_OrginalValue", m2.get("OrginalValue"));//监测因子对应值
                        } else {
                            m1.put(m2.get("ItemCode") + "_Val", null);//监测因子对应值
                            m1.put(m2.get("ItemCode") + "_OrginalValue", null);//监测因子对应值
                        }

                        m1.put(m2.get("ItemCode") + "_IsOver", m2.get("IsOver"));//监测参数是否超标
                        m1.put(m2.get("ItemCode") + "_OverTimes", m2.get("OverTimes"));//监测值超标倍数
                        m1.put(m2.get("ItemCode") + "_qualityLevel", m2.get("itemQualityLevel"));//监测值超标倍数
                        m1.put(m2.get("ItemCode") + "_qualityLevelName", m2.get("itemQualityLevelName"));//监测值超标倍数
                        m1.put("SegmentID", m2.get("SegmentID"));//断面id
                        Object qualityLevelName = m2.get("QualityLevel");
                        if (qualityLevelName != null && !"".equals(qualityLevelName) && Integer.valueOf(String.valueOf(qualityLevelName)) > 0) {
                            m1.put("IsOvers", m2.get("IsOvers"));//断面id
                        } else {
                            m1.put("IsOvers", "");//断面id
                        }

                        m1.put("SegmentName", m2.get("SegmentName"));//断面名称

                        m1.put("id", m2.get("SegmentID"));
                        m1.put("siteType", "IsManual");
                        m1.put("segmentName", m2.get("SegmentName"));

                        m1.put("QualityLevel", m2.get("QualityLevel"));//断面水质级别
                        m1.put("Level", m2.get("QualityLevelName"));//断面水质级别
                        m1.put("TargetLevel", m2.get("TargetLevelName"));//断面目标级别
                        m1.put("dataSource", m2.get("dataSource"));//数据来源
                        m1.put("SampleDate", m2.get("SampleDate"));//监测时间
                        m1.put("moonSampleDate", m2.get("moonSampleDate"));//监测时间
                        m1.put("yeraSampleDate", m2.get("yeraSampleDate"));//监测时间
                        m1.put("RiverName", m2.get("RiverName"));//河流名称
                        m1.put("RiverID", m2.get("RiverID"));//河流id
                        m1.put("type", "当期");//监测时间
                        m1.put("longitude", m2.get("longitude"));//经度
                        m1.put("latitude", m2.get("latitude"));//纬度

                        //是否超标
                        String isEvalute = String.valueOf(itemEvaluteList.get(0).get("isEvalute"));
                        if ("1".equals(isEvalute)) {
                            String isoverstandard = String.valueOf(m2.get("IsOver"));
//                           BigDecimal effectivevalue= hourdata.getEffectivevalue();
                            String overstandardtimes = String.valueOf(m2.get("OverTimes"));
                            if ("1".equals(isoverstandard)) {
                                Map<String, Object> overMap = new HashMap<>();
                                overMap.put("itemName", itemName);
                                overMap.put("value", dfql.format(effectiveValue));
                                if (StringUtils.isNotEmpty(overstandardtimes) && !"null".equals(overstandardtimes) && !"--".equals(overstandardtimes)) {
                                    overMap.put("overstandardtimes", overstandardtimes);
                                } else {
                                    overMap.put("overstandardtimes", "");
                                }
                                Object standardValue = "";
                                if ("15DE941F-A221-4D9C-8387-48B0E99F6E25".equals(String.valueOf(m2.get("ItemCode")).toUpperCase())) {
                                    standardValue = "6~9";//监测因子对应值

                                } else {
                                    if (StringUtils.isNotEmpty(sunmapsWaterTypelist) && sunmapsWaterTypelist.size() > 0) {
                                        standardValue = sunmapsWaterTypelist.get(0).get("standardValue");
                                    }
                                }
                                overMap.put("standardValue", standardValue);
                                overMap.put("unit", Unit);

                                overStandardFactors.add(overMap);
                            }
                        }


                        Object assessType = m2.get("AssessTypeCode");
                        Object targetLevel = m2.get("PollutionItem");
                        //  Object qualityLevelName = m2.get("QualityLevel");
                        if (!"无类别".equals(qualityLevelName) && qualityLevelName != null && !"".equals(qualityLevelName) && Integer.valueOf(String.valueOf(qualityLevelName)) > 0 && targetLevel != null && !"".equals(targetLevel)) {
                            m1.put("SegmentIsOver", "超标");//监测时间
                        } else if (!"无类别".equals(qualityLevelName) && qualityLevelName != null && !"".equals(qualityLevelName) && Integer.valueOf(String.valueOf(qualityLevelName)) > 0) {
                            m1.put("SegmentIsOver", "达标");//监测时间
                        } else {
                            m1.put("SegmentIsOver", "");//监测时间
                        }
                        //水质评价
                        m1.put("waterQuality", m2.get("waterQuality"));
                        //水质指数
                        Object segmentIndex = m2.get("segmentIndex");
                        if (segmentIndex != null && !"".equals(segmentIndex) && Double.valueOf(String.valueOf(segmentIndex)) > 0) {
                            m1.put("segmentIndex", df.format(segmentIndex));
                        }

                        //水质趋势
                        m1.put("evaluationTrendCode", m2.get("evaluationTrendCode"));
                        m1.put("evaluationTrend", m2.get("evaluationTrend"));

                        String min = "";
                        if (assessType != null && !"".equals(assessType)) {
                            String[] split = String.valueOf(assessType).split(",");
                            min = split[0];
                            for (int i = 1; i < split.length; i++) {
                                if (Integer.parseInt(min) < Integer.parseInt(split[i])) { //最大/最小 根据需求更改 大于号或小于号 即可
                                    min = split[i];
                                }
                            }
                        }
                        if (min != null && !"".equals(min)) {
                            if (min.equals("0")) {
                                m1.put("AssessType", "国考");//考核类型编码(0 国考 1省考 2市考)
                            }
                            if (min.equals("1")) {
                                m1.put("AssessType", "省考");//考核类型编码(0 国考 1省考 2市考)
                            }
                            if (min.equals("2")) {
                                m1.put("AssessType", "市考");//考核类型编码(0 国考 1省考 2市考)
                            }
                        } else {
                            m1.put("AssessType", "");
                        }

                        m1.put("ControlLevel", m2.get("ControlLevel"));//控制级别（国控/省控/市控）
                        m1.put("ControlLevelCode", m2.get("ControlLevelCode"));//控制级别（国控/省控/市控）
                        m2.clear();
                    });
            if (StringUtils.isNotEmpty(overStandardFactors) && overStandardFactors.size() > 0) {
                for (Map<String, Object> retMap : overStandardFactors) {
                    Object itemName = retMap.get("itemName");
                    Object value = retMap.get("value");
                    Object standardValue = retMap.get("standardValue");
                    Object unit = retMap.get("unit");

//                   Object overstandardtimes= retMap.get("overstandardtimes");
                    overMessage = overMessage + itemName + "(监测值：" + value + unit;
//                    if(StringUtils.isNotNull(overstandardtimes) && !"".equals(overstandardtimes) && !"null".equals(overstandardtimes) && !"--".equals(overstandardtimes)){
//                        overMessage=overMessage+",倍数："+overstandardtimes;
//                    }
                    if (StringUtils.isNotNull(standardValue) && !"".equals(standardValue) && !"null".equals(standardValue) && !"--".equals(standardValue)) {
                        overMessage = overMessage + ",标准值：" + standardValue + unit;
                    }
                    overMessage = overMessage + ")、";
                }
            }
            if (StringUtils.isNotEmpty(overMessage)) {
                m1.put("overstandarddescribe", overMessage.substring(0, overMessage.length() - 1));
            } else {
                m1.put("overstandarddescribe", "");
            }

            return m1;
        }).collect(Collectors.toList());
        //   System.out.println(System.currentTimeMillis() - t1);
        if (resultList != null && resultList.size() > 0) {
            for (Map<String, Object> data : resultList) {
                Object segmentName = data.get("SegmentName");
                if (segmentName != null && !"".equals(segmentName)) {
                    listdata.add(data);
                }
            }
        }
        List<Map<String, Object>> list = new ArrayList<>();
        if (listdata != null && listdata.size() > 0) {
            list = ListDataUtil.twoObjectascendingOrder(listdata, "SegmentName", "SampleDate");

        }

        List<Map<String, Object>> retList = PageUtil.startListPage(list, vo.getPageNum(), vo.getPageSize()).getList();

        return retList;
    }

    @Override
    public Map<String, Object> surfaceWaterListData(MultipartFile file, String sheetName, String prop) {
        Map<String, Object> map = new HashMap<>();
        map.put("msg", "上传数据成功");
        map.put("code", 200);

        SimpleDateFormat formats = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat nyformats = new SimpleDateFormat("yyyy-MM-dd");
        ExcelUtiles excel = new ExcelUtiles();//excel文件工具类
        //根据传入的数据类型编码查询对应数据类型名称
        String bussinessCategory = null;
        Map wqcodbussinessitemsName = new HashMap();
        wqcodbussinessitemsName.put("bussinessCategoryCode", prop);//数据类型编码
        List<Map> wqcodbussinessitemsNamelist = publicToolsMapper.wqcodbussinessitemsName(wqcodbussinessitemsName);
        if (wqcodbussinessitemsNamelist != null && wqcodbussinessitemsNamelist.size() > 0) {
            bussinessCategory = (String) wqcodbussinessitemsNamelist.get(0).get("BussinessCategory");//获取数据类型名称
        }
        //是否修约
        String isround = null;
        SysConfig sysConfig = new SysConfig();
        sysConfig.setConfigKey("sys.manualData.round");
        SysConfig sysConfig1 = sysConfigMapper.selectConfig(sysConfig);
        if (sysConfig1 != null) {
            isround = sysConfig1.getConfigValue();
        }

//        Map<String, Object> maplist = new HashMap<>();//存放返回值
//        List<Map<String, Object>> list = new ArrayList();//存放所有断面处理后的数据
        String fileName = file.getOriginalFilename();
        //获取文件后缀
        String extension = "." + FilenameUtils.getExtension(fileName);
        //生成新的文件名称
        String newFileName = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + UUID.randomUUID().toString().replace("-", "") + extension;
        // 根据日期生成目录
        String format = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
        // 本地资源路径
        String localPath = ruoYiConfig.getProfile();
        String dateDirPath = localPath;
        File dateDir = new File(dateDirPath);
        if (!dateDir.exists())
            dateDir.mkdirs();
        File dir = new File(dateDirPath);
        // 处理文件上传
        try {
            file.transferTo(new File(dir, newFileName));
        } catch (IOException e) {
            e.printStackTrace();
        }
        String s = dir + "/" + newFileName;
        Integer sheetNumdata = 0;
        //获取对应shell页 1.根据文件获取对应shell页在根据传入的shell页名称获取对应位置
        List<Map<String, Object>> excelFileShellmaps = excel.excelFileShellurl(s);
        if (excelFileShellmaps != null && excelFileShellmaps.size() > 0) {
            for (Map excelFileShellmapss : excelFileShellmaps) {
                Object sheetName1 = excelFileShellmapss.get("sheetName");//shell名称
                Object sheetNum = excelFileShellmapss.get("sheetNum");//shell位置
                if (sheetName1.equals(sheetName)) {
                    sheetNumdata = Integer.valueOf(String.valueOf(sheetNum));
                }
            }
        }
        //存放模板中临时数据
        //List<WqDataTempdata> WqDataTempdatalist=new ArrayList<>();
        List<Map<String, Object>> WqDataTempdatalist = new ArrayList<>();
        String ReportID = UUID.randomUUID().toString();
        //用于判断模板标题是否已经插入
        int tabulation = 1;
        String ItemName = null;
        //根据已经上传的excel文件调用poi进行转换
        try (InputStream is = new FileInputStream(s);
             Workbook workbook = new XSSFWorkbook(is)) {
            //获取指定sheet页
            Sheet sheet = workbook.getSheetAt(sheetNumdata);
            Row headerRow = sheet.getRow(0);
            //查询这个sheet页里面有多少条数据
            int numRows = sheet.getPhysicalNumberOfRows();
            Map<String, Object> WqDataTempdatatabulation = new HashMap<>();
            for (int rowIndex = 1; rowIndex < numRows; rowIndex++) {
                Row row = sheet.getRow(rowIndex);
                Map<String, Object> dataMap = new HashMap<>();
                //存放临时数据
                Map<String, Object> WqDataTempdata = new HashMap<>();
                //存放模板标题
                //如果存在监测值就进行加一
                int Number = 1;
                //查询年月日拼接
                String dataTime = null;
                Boolean itemi = false;
                for (int columnIndex = 0; columnIndex < headerRow.getLastCellNum(); columnIndex++) {
                    Cell headerCell = headerRow.getCell(columnIndex);
                    Object cell = excel.getCellValue(row, columnIndex);
                    //Cell cell = row.getCell(columnIndex);//获取对应位置的值
                    //获取key值列表名称
                    String headerCellValue = headerCell.getStringCellValue();
                    if (headerCellValue != null && !"".equals(headerCellValue)) {
                        String cellValue = "";
                        //查询断面id
                        if (headerCellValue != null && headerCellValue.equals("监测断面") || headerCellValue.equals("断面名称")) {
                            if (cell != null) {
                                String SegmentName = String.valueOf(cell);//断面名称
                                Map WqBasSegmentNameAll = new HashMap();
                                WqBasSegmentNameAll.put("segmentName", SegmentName);//断面名称
                                WqBasSegmentNameAll.put("segmentType", "IsManual");//断面类型手工
                                List<Map> segmentNamelist = publicToolsMapper.WqBasSegmentNamedrExcel(WqBasSegmentNameAll);
                                if (segmentNamelist != null && segmentNamelist.size() > 0) {
                                    String id = (String) segmentNamelist.get(0).get("ID");//获取断面id
                                    WqDataTempdata.put("SegmentID", id);
                                }
                                WqDataTempdatatabulation.put("SegmentName", "监测断面");
                                WqDataTempdata.put("SegmentName", SegmentName);

                            }
                        }
                        if (headerCellValue != null && headerCellValue.equals("经度")) {
                            if (cell != null) {
                                String longitude = String.valueOf(cell);//经度
                                WqDataTempdatatabulation.put("longitude", "经度");
                                if (longitude != null && !"".equals(longitude)) {
                                    WqDataTempdata.put("longitude", longitude);//经度
                                } else {
                                    WqDataTempdata.put("longitude", null);//经度
                                }
                            }
                        }
                        if (headerCellValue != null && headerCellValue.equals("纬度")) {
                            if (cell != null) {
                                String longitude = String.valueOf(cell);//经度
                                WqDataTempdatatabulation.put("latitude", "纬度");
                                if (longitude != null && !"".equals(longitude)) {
                                    WqDataTempdata.put("latitude", longitude);//经度
                                } else {
                                    WqDataTempdata.put("latitude", null);//经度
                                }
                            }
                        }

                        if (headerCellValue != null && headerCellValue.equals("数据来源")) {
                            if (cell != null) {
                                String dataSource = String.valueOf(cell);//数据来源
                                WqDataTempdatatabulation.put("dataSource", "数据来源");
                                if (dataSource != null && !"".equals(dataSource)) {
                                    WqDataTempdata.put("dataSource", dataSource);//数据来源
                                } else {
                                    WqDataTempdata.put("dataSource", null);//数据来源
                                }
                            }
                        }

                        if (headerCellValue != null && headerCellValue.equals("采样点") || headerCellValue.equals("水平采样方位")) {
                            if (cell != null) {
                                String HorizontalAzimuth = String.valueOf(cell);//采样点
                                WqDataTempdatatabulation.put("HorizontalAzimuth", "水平采样方位");
                                if (HorizontalAzimuth != null && !"".equals(HorizontalAzimuth)) {
                                    WqDataTempdata.put("HorizontalAzimuth", HorizontalAzimuth);
                                } else {
                                    WqDataTempdata.put("HorizontalAzimuth", "表");
                                }


                            }
                        } else if (headerCellValue != null && headerCellValue.equals("垂直采样方位")) {
                            if (cell != null) {
                                String VerticalAzimuth = String.valueOf(cell);//采样点
                                WqDataTempdatatabulation.put("VerticalAzimuth", "垂直采样方位");
                                WqDataTempdata.put("VerticalAzimuth", VerticalAzimuth);

                            }
                        }
                        if (prop.equals("CBN")) {
                            //查询年月日拼接
                            //String dataTime=null;
                            if (headerCellValue != null && headerCellValue.equals("年") || headerCellValue.equals("年度")) {
                                if (cell != null) {
                                    String value = String.valueOf(cell);//年
                                    if (dataTime == null && !"-1".equals(value) && value.length() >= 4) {
                                        dataTime = value;
                                    } else {
                                        map.put("msg", "时间格式错误");
                                        break;
                                    }
                                }
                            }
                            if (headerCellValue != null && headerCellValue.equals("月")) {
                                if (cell != null) {
                                    String value = String.valueOf(cell);//月
                                    if (dataTime != null && !"-1".equals(value) && value.length() >= 1) {
                                        dataTime = dataTime + "-" + value;
                                    } else {
                                        map.put("msg", "时间格式错误");
                                        break;
                                    }
                                }
                            }
                            if (headerCellValue != null && headerCellValue.equals("日")) {
                                if (cell != null) {
                                    String value = String.valueOf(cell);//日
                                    if (dataTime != null && !"-1".equals(value) && value.length() >= 1) {
                                        dataTime = dataTime + "-" + value;
                                    } else {
                                        map.put("msg", "时间格式错误");
                                        break;
                                    }
                                }

                            }
                            if (headerCellValue != null && headerCellValue.equals("时")) {
                                if (cell != null) {
                                    String value = String.valueOf(cell);//时
                                    if (dataTime != null && !"-1".equals(value) && value.length() >= 1) {
                                        dataTime = dataTime + " " + value;
                                    } else {
                                        map.put("msg", "时间格式错误");
                                        break;
                                    }
                                }

                            }
                            if (headerCellValue != null && headerCellValue.equals("分")) {
                                if (cell != null) {
                                    String value = String.valueOf(cell);//分
                                    if (dataTime != null && !"-1".equals(value) && value.length() >= 1) {
                                        dataTime = dataTime + ":" + value;
                                    } else {
                                        map.put("msg", "时间格式错误");
                                        break;
                                    }
                                }

                            }
                            if (headerCellValue != null && headerCellValue.equals("秒")) {
                                if (cell != null) {
                                    String value = String.valueOf(cell);//秒
                                    if (dataTime != null && !"-1".equals(value) && value.length() >= 2) {
                                        dataTime = dataTime + ":" + value;
                                    } else if (dataTime != null && !"-1".equals(value) && value.length() >= 1) {
                                        dataTime = dataTime + ":0" + value;
                                    } else {
                                        map.put("msg", "时间格式错误");
                                        break;
                                    }
                                }
                                if (dataTime != null && !"".equals(dataTime)) {
                                    try {
                                        Date parse = nyformats.parse(dataTime);
                                        String value = nyformats.format(parse);
                                        if (dataTime == null && !"-1".equals(value)) {
                                            dataTime = value;
                                        }
                                    } catch (Exception e) {
                                        map.put("msg", "时间格式错误");
                                        break;
                                        // 尝试下一个模式
                                    }
                                }
                            }

                            if (headerCellValue != null && headerCellValue.equals("监测时间") || headerCellValue.equals("采样时间")) {
                                if (cell != null) {
                                    String s1 = String.valueOf(cell);
                                    if (s1 != null && !"".equals(s1)) {
                                        try {
                                            Date parse = DateUtils.dateTime("yyyy-MM-dd HH:mm", s1);
                                            String value = formats.format(parse);
                                            if (dataTime == null && !"-1".equals(value)) {
                                                dataTime = value;
                                            }
                                        } catch (Exception e) {
                                            try {
                                                Date parse = nyformats.parse(s1);
                                                String value = nyformats.format(parse);
                                                if (dataTime == null && !"-1".equals(value)) {
                                                    dataTime = value;
                                                }

                                            } catch (Exception es) {
                                                try {
                                                    String value = formats.format(cell);
                                                    if (dataTime == null && !"-1".equals(value)) {
                                                        dataTime = value;
                                                    }
                                                } catch (Exception se) {
                                                    try {
                                                        String value = nyformats.format(cell);
                                                        if (dataTime == null && !"-1".equals(value)) {
                                                            dataTime = value;
                                                        }
                                                    } catch (Exception ses) {

                                                        map.put("msg", "时间格式错误");
                                                        break;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            if (headerCellValue != null && headerCellValue.equals("采样日期")) {
                                if (cell != null) {
                                    String s1 = String.valueOf(cell);
                                    if (s1 != null && !"".equals(s1)) {
                                        try {
                                            Date parse = DateUtils.dateTime("yyyy-MM-dd", s1);
                                            String value = nyformats.format(parse);
                                            if (dataTime == null && !"-1".equals(value)) {
                                                dataTime = value;
                                            }
                                        } catch (Exception e) {
                                            map.put("msg", "时间格式错误");
                                            break;
                                        }
                                    }
                                }
                            }
                            if (headerCellValue != null && headerCellValue.equals("时间")) {
                                if (cell != null) {
                                    String value = String.valueOf(cell);//秒
                                    if (dataTime != null && !"-1".equals(value) && value.length() >= 1) {
                                        dataTime = dataTime + " " + value;
                                    }  else {
                                        dataTime = dataTime + " 00:00";
                                    }
                                }else{
                                    dataTime = dataTime + " 00:00";
                                }
                                if (dataTime != null && !"".equals(dataTime)) {
                                    try {
                                        Date parse = DateUtils.dateTime("yyyy-MM-dd HH:mm",dataTime);
                                        String value = DateUtils.dateFormat(parse,"yyyy-MM-dd HH:mm:ss");
                                        if (dataTime == null && !"-1".equals(value)) {
                                            dataTime = value;
                                        }
                                    } catch (Exception e) {
                                        map.put("msg", "时间格式错误");
                                        break;
                                        // 尝试下一个模式
                                    }
                                }
                            }

                        } else if (prop.equals("CBN3")) {
                            if (headerCellValue != null && headerCellValue.equals("年") || headerCellValue.equals("年度")) {
                                if (cell != null) {
                                    String value = String.valueOf(cell);//年
                                    if (dataTime == null && !"-1".equals(value) && value.length() >= 4) {
                                        dataTime = value;
                                    } else {
                                        map.put("msg", "时间格式错误");
                                        break;
                                    }
                                }
                            }
                            if (headerCellValue != null && headerCellValue.equals("月")) {
                                if (cell != null) {
                                    String value = String.valueOf(cell);//月
                                    if (dataTime != null && !"-1".equals(value) && value.length() >= 1) {
                                        dataTime = dataTime + "-" + value;
                                    } else {
                                        map.put("msg", "时间格式错误");
                                        break;
                                    }
                                }
                            }
                            if (headerCellValue != null && headerCellValue.equals("日")) {
                                if (cell != null) {
                                    String value = String.valueOf(cell);//日
                                    if (dataTime != null && !"-1".equals(value) && value.length() >= 1) {
                                        dataTime = dataTime + "-" + value;
                                    }
                                }
                                if (dataTime != null && !"".equals(dataTime)) {
                                    try {
                                        Date parse = nyformats.parse(dataTime);
                                        String value = nyformats.format(parse);
                                        if (dataTime == null && !"-1".equals(value)) {
                                            dataTime = value;
                                        }
                                    } catch (Exception e) {
                                        map.put("msg", "时间格式错误");
                                        break;
                                        // 尝试下一个模式
                                    }
                                }
                            }
                            if (headerCellValue != null && headerCellValue.equals("监测时间") || headerCellValue.equals("采样时间")) {
                                if (cell != null) {
                                    String s1 = String.valueOf(cell);
                                    if (s1 != null && !"".equals(s1)) {
                                        try {
                                            Date parse = DateUtils.dateTime("yyyy-MM-dd HH:mm", s1);
                                            String value = formats.format(parse);
                                            if (dataTime == null && !"-1".equals(value)) {
                                                dataTime = value;
                                            }
                                        } catch (Exception e) {
                                            try {
                                                Date parse = nyformats.parse(s1);
                                                String value = nyformats.format(parse);
                                                if (dataTime == null && !"-1".equals(value)) {
                                                    dataTime = value;
                                                }

                                            } catch (Exception es) {
                                                try {
                                                    String value = formats.format(cell);
                                                    if (dataTime == null && !"-1".equals(value)) {
                                                        dataTime = value;
                                                    }
                                                } catch (Exception se) {
                                                    try {
                                                        String value = nyformats.format(cell);
                                                        if (dataTime == null && !"-1".equals(value)) {
                                                            dataTime = value;
                                                        }
                                                    } catch (Exception ses) {

                                                        map.put("msg", "时间格式错误");
                                                        break;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            if (headerCellValue != null && headerCellValue.equals("采样日期")) {
                                if (cell != null) {
                                    String s1 = String.valueOf(cell);
                                    if (s1 != null && !"".equals(s1)) {
                                        try {
                                            Date parse = DateUtils.dateTime("yyyy-MM-dd", s1);
                                            String value = nyformats.format(parse);
                                            if (dataTime == null && !"-1".equals(value)) {
                                                dataTime = value;
                                            }
                                        } catch (Exception e) {
                                            map.put("msg", "时间格式错误");
                                            break;
                                        }
                                    }
                                }
                            }
                            if (headerCellValue != null && headerCellValue.equals("时间")) {
                                if (cell != null) {
                                    String value = String.valueOf(cell);//秒
                                    if (dataTime != null && !"-1".equals(value) && value.length() >= 1) {
                                        dataTime = dataTime + " " + value;
                                    }  else {
                                        dataTime = dataTime + " 00:00";
                                    }
                                }else{
                                    dataTime = dataTime + " 00:00";
                                }
                                if (dataTime != null && !"".equals(dataTime)) {
                                    try {
                                        Date parse = DateUtils.dateTime("yyyy-MM-dd HH:mm",dataTime);
                                        String value = DateUtils.dateFormat(parse,"yyyy-MM-dd HH:mm:ss");
                                        if (dataTime == null && !"-1".equals(value)) {
                                            dataTime = value;
                                        }
                                    } catch (Exception e) {
                                        map.put("msg", "时间格式错误");
                                        break;
                                        // 尝试下一个模式
                                    }
                                }
                            }
                        } else if (prop.equals("CBF1")) {
                            //查询年月日拼接
                            //String dataTime=null;
                            if (headerCellValue != null && headerCellValue.equals("年") || headerCellValue.equals("年度")) {
                                if (cell != null) {
                                    String value = String.valueOf(cell);//年
                                    if (dataTime == null && !"-1".equals(value) && value.length() >= 4) {
                                        dataTime = value;
                                    } else {
                                        map.put("msg", "时间格式错误");
                                        break;
                                    }
                                }
                            }
                            if (headerCellValue != null && headerCellValue.equals("月")) {
                                if (cell != null) {
                                    String value = String.valueOf(cell);//月
                                    if (dataTime != null && !"-1".equals(value) && value.length() >= 1) {
                                        dataTime = dataTime + "-" + value;
                                    } else {
                                        map.put("msg", "时间格式错误");
                                        break;
                                    }
                                }
                            }
                            if (headerCellValue != null && headerCellValue.equals("日")) {
                                if (cell != null) {
                                    String value = String.valueOf(cell);//日
                                    if (dataTime != null && !"-1".equals(value) && value.length() >= 1) {
                                        dataTime = dataTime + "-" + value;
                                    } else {
                                        map.put("msg", "时间格式错误");
                                        break;
                                    }
                                }
//                                if(dataTime!=null&&!"".equals(dataTime)){
//                                    try {
//                                        Date parse = nyformats.parse(dataTime);
//                                        String value = nyformats.format(parse);
//                                        if (dataTime == null && !"-1".equals(value)) {
//                                            dataTime = value;
//                                        }
//                                    } catch (Exception e) {
//                                        map.put("msg", "时间格式错误");
//                                        break;
//                                        // 尝试下一个模式
//                                    }
//                                }
                            }

                            if (headerCellValue != null && headerCellValue.equals("时")) {
                                if (cell != null) {
                                    String value = String.valueOf(cell);//时
                                    if (dataTime != null && !"-1".equals(value) && value.length() >= 1) {
                                        dataTime = dataTime + " " + value;
                                    } else {
                                        map.put("msg", "时间格式错误");
                                        break;
                                    }
                                }

                            }
                            if (headerCellValue != null && headerCellValue.equals("分")) {
                                if (cell != null) {
                                    String value = String.valueOf(cell);//分
                                    if (dataTime != null && !"-1".equals(value) && value.length() >= 1) {
                                        dataTime = dataTime + ":" + value;
                                    } else {
                                        map.put("msg", "时间格式错误");
                                        break;
                                    }
                                }

                            }
                            if (headerCellValue != null && headerCellValue.equals("秒")) {
                                if (cell != null) {
                                    String value = String.valueOf(cell);//秒
                                    if (dataTime != null && !"-1".equals(value) && value.length() >= 2) {
                                        dataTime = dataTime + ":" + value;
                                    } else if (dataTime != null && !"-1".equals(value) && value.length() >= 1) {
                                        dataTime = dataTime + ":0" + value;
                                    } else {
                                        map.put("msg", "时间格式错误");
                                        break;
                                    }
                                }
                                if (dataTime != null && !"".equals(dataTime)) {
                                    try {
                                        Date parse = nyformats.parse(dataTime);
                                        String value = nyformats.format(parse);
                                        if (dataTime == null && !"-1".equals(value)) {
                                            dataTime = value;
                                        }
                                    } catch (Exception e) {
                                        map.put("msg", "时间格式错误");
                                        break;
                                        // 尝试下一个模式
                                    }
                                }
                            }
                            if (headerCellValue != null && headerCellValue.equals("监测时间") || headerCellValue.equals("采样时间")) {
                                if (cell != null) {
                                    String s1 = String.valueOf(cell);
                                    if (s1 != null && !"".equals(s1)) {
                                        try {
                                            Date parse = DateUtils.dateTime("yyyy-MM-dd HH:mm", s1);
                                            String value = formats.format(parse);
                                            if (dataTime == null && !"-1".equals(value)) {
                                                dataTime = value;
                                            }
                                        } catch (Exception e) {
                                            try {
                                                Date parse = nyformats.parse(s1);
                                                String value = nyformats.format(parse);
                                                if (dataTime == null && !"-1".equals(value)) {
                                                    dataTime = value;
                                                }

                                            } catch (Exception es) {
                                                try {
                                                    String value = formats.format(cell);
                                                    if (dataTime == null && !"-1".equals(value)) {
                                                        dataTime = value;
                                                    }
                                                } catch (Exception se) {
                                                    try {
                                                        String value = nyformats.format(cell);
                                                        if (dataTime == null && !"-1".equals(value)) {
                                                            dataTime = value;
                                                        }
                                                    } catch (Exception ses) {

                                                        map.put("msg", "时间格式错误");
                                                        break;
                                                    }

                                                }

                                            }
                                            // 尝试下一个模式
                                        }
                                    }
                                    // String value = String.valueOf(cell);//

                                }
                            }
                            if (headerCellValue != null && headerCellValue.equals("采样日期")) {
                                if (cell != null) {
                                    String s1 = String.valueOf(cell);
                                    if (s1 != null && !"".equals(s1)) {
                                        try {
                                            Date parse = DateUtils.dateTime("yyyy-MM-dd", s1);
                                            String value = nyformats.format(parse);
                                            if (dataTime == null && !"-1".equals(value)) {
                                                dataTime = value;
                                            }
                                        } catch (Exception e) {
                                            map.put("msg", "时间格式错误");
                                            break;
                                        }
                                    }
                                }
                            }
                            if (headerCellValue != null && headerCellValue.equals("时间")) {
                                if (cell != null) {
                                    String value = String.valueOf(cell);//秒
                                    if (dataTime != null && !"-1".equals(value) && value.length() >= 1) {
                                        dataTime = dataTime + " " + value;
                                    }  else {
                                        dataTime = dataTime + " 00:00";
                                    }
                                }else{
                                    dataTime = dataTime + " 00:00";
                                }
                                if (dataTime != null && !"".equals(dataTime)) {
                                    try {
                                        Date parse = DateUtils.dateTime("yyyy-MM-dd HH:mm",dataTime);
                                        String value = DateUtils.dateFormat(parse,"yyyy-MM-dd HH:mm:ss");
                                        if (dataTime == null && !"-1".equals(value)) {
                                            dataTime = value;
                                        }
                                    } catch (Exception e) {
                                        map.put("msg", "时间格式错误");
                                        break;
                                        // 尝试下一个模式
                                    }
                                }
                            }
                        } else if (prop.equals("CBF8")) {
                            //查询年月日拼接
                            //String dataTime=null;
                            if (headerCellValue != null && headerCellValue.equals("年") || headerCellValue.equals("年度")) {
                                if (cell != null) {
                                    String value = String.valueOf(cell);//年
                                    if (dataTime == null && !"-1".equals(value) && value.length() >= 4) {
                                        dataTime = value;
                                    } else {
                                        map.put("msg", "时间格式错误");
                                        break;
                                    }
                                }
                            }
                            if (headerCellValue != null && headerCellValue.equals("月")) {
                                if (cell != null) {
                                    String value = String.valueOf(cell);//月
                                    if (dataTime != null && !"-1".equals(value) && value.length() >= 1) {
                                        dataTime = dataTime + "-" + value;
                                    } else {
                                        map.put("msg", "时间格式错误");
                                        break;
                                    }
                                }
                            }
                            if (headerCellValue != null && headerCellValue.equals("日")) {
                                if (cell != null) {
                                    String value = String.valueOf(cell);//日
                                    if (dataTime != null && !"-1".equals(value) && value.length() >= 1) {
                                        dataTime = dataTime + "-" + value;
                                    } else {
                                        map.put("msg", "时间格式错误");
                                        break;
                                    }
                                }
//                                if(dataTime!=null&&!"".equals(dataTime)){
//                                    try {
//                                        Date parse = nyformats.parse(dataTime);
//                                        String value = nyformats.format(parse);
//                                        if (dataTime == null && !"-1".equals(value)) {
//                                            dataTime = value;
//                                        }
//                                    } catch (Exception e) {
//                                        map.put("msg", "时间格式错误");
//                                        break;
//                                        // 尝试下一个模式
//                                    }
//                                }
                            }
                            if (headerCellValue != null && headerCellValue.equals("时")) {
                                if (cell != null) {
                                    String value = String.valueOf(cell);//时
                                    if (dataTime != null && !"-1".equals(value) && value.length() >= 1) {
                                        dataTime = dataTime + " " + value;
                                    } else {
                                        map.put("msg", "时间格式错误");
                                        break;
                                    }
                                }

                            }
                            if (headerCellValue != null && headerCellValue.equals("分")) {
                                if (cell != null) {
                                    String value = String.valueOf(cell);//分
                                    if (dataTime != null && !"-1".equals(value) && value.length() >= 1) {
                                        dataTime = dataTime + ":" + value;
                                    } else {
                                        map.put("msg", "时间格式错误");
                                        break;
                                    }
                                }

                            }
                            if (headerCellValue != null && headerCellValue.equals("秒")) {
                                if (cell != null) {
                                    String value = String.valueOf(cell);//秒
                                    if (dataTime != null && !"-1".equals(value) && value.length() >= 2) {
                                        dataTime = dataTime + ":" + value;
                                    } else if (dataTime != null && !"-1".equals(value) && value.length() >= 1) {
                                        dataTime = dataTime + ":0" + value;
                                    } else {
                                        map.put("msg", "时间格式错误");
                                        break;
                                    }
                                }
                                if (dataTime != null && !"".equals(dataTime)) {
                                    try {
                                        Date parse = nyformats.parse(dataTime);
                                        String value = nyformats.format(parse);
                                        if (dataTime == null && !"-1".equals(value)) {
                                            dataTime = value;
                                        }
                                    } catch (Exception e) {
                                        map.put("msg", "时间格式错误");
                                        break;
                                        // 尝试下一个模式
                                    }
                                }
                            }

                            if (headerCellValue != null && headerCellValue.equals("监测时间") || headerCellValue.equals("采样时间")) {
                                if (cell != null) {
                                    String s1 = String.valueOf(cell);
                                    if (s1 != null && !"".equals(s1)) {
                                        try {
                                            Date parse = DateUtils.dateTime("yyyy-MM-dd HH:mm", s1);
                                            String value = formats.format(parse);
                                            if (dataTime == null && !"-1".equals(value)) {
                                                dataTime = value;
                                            }
                                        } catch (Exception e) {
                                            try {
                                                Date parse = nyformats.parse(s1);
                                                String value = nyformats.format(parse);
                                                if (dataTime == null && !"-1".equals(value)) {
                                                    dataTime = value;
                                                }

                                            } catch (Exception es) {
                                                try {
                                                    String value = formats.format(cell);
                                                    if (dataTime == null && !"-1".equals(value)) {
                                                        dataTime = value;
                                                    }
                                                } catch (Exception se) {
                                                    try {
                                                        String value = nyformats.format(cell);
                                                        if (dataTime == null && !"-1".equals(value)) {
                                                            dataTime = value;
                                                        }
                                                    } catch (Exception ses) {

                                                        map.put("msg", "时间格式错误");
                                                        break;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            if (headerCellValue != null && headerCellValue.equals("采样日期")) {
                                if (cell != null) {
                                    String s1 = String.valueOf(cell);
                                    if (s1 != null && !"".equals(s1)) {
                                        try {
                                            Date parse = DateUtils.dateTime("yyyy-MM-dd", s1);
                                            String value = nyformats.format(parse);
                                            if (dataTime == null && !"-1".equals(value)) {
                                                dataTime = value;
                                            }
                                        } catch (Exception e) {
                                            map.put("msg", "时间格式错误");
                                            break;
                                        }
                                    }
                                }
                            }
                            if (headerCellValue != null && headerCellValue.equals("时间")) {
                                if (cell != null) {
                                    String value = String.valueOf(cell);//秒
                                    if (dataTime != null && !"-1".equals(value) && value.length() >= 1) {
                                        dataTime = dataTime + " " + value;
                                    }  else {
                                        dataTime = dataTime + " 00:00";
                                    }
                                }else{
                                    dataTime = dataTime + " 00:00";
                                }
                                if (dataTime != null && !"".equals(dataTime)) {
                                    try {
                                        Date parse = DateUtils.dateTime("yyyy-MM-dd HH:mm",dataTime);
                                        String value = DateUtils.dateFormat(parse,"yyyy-MM-dd HH:mm:ss");
                                        if (dataTime == null && !"-1".equals(value)) {
                                            dataTime = value;
                                        }
                                    } catch (Exception e) {
                                        map.put("msg", "时间格式错误");
                                        break;
                                        // 尝试下一个模式
                                    }
                                }
                            }
                        }

                        if ("pH".equals(headerCellValue)) {
                            itemi = true;
                        }
                        if (itemi && !"备注".equals(headerCellValue)) {
                            String Value = "value" + Number;
                            WqDataTempdatatabulation.put(Value, headerCellValue);
                            if (cell != null) {
                                String value = String.valueOf(cell);//监测值数据
                                if (value != null && !"".equals(value)) {

                                } else {
                                    value = "-1";
                                }

                                //isround 1 修约，0 不修约bussinessCategoryData
                                if (!"-1".equals(value) && StringUtils.isNotEmpty(isround) && isround.equals("1") && !StringUtils.validateCharacterExist(value)) {
                                    //满足修约条件，进行修约
                                    for (Map<String, Object> itemmap : wqcodbussinessitemsNamelist) {
                                        String itemName1 = itemmap.get("ItemName") == null ? "" : itemmap.get("ItemName").toString();
                                        if (itemName1.equals(headerCellValue)) {
                                            String KeepPointBits = itemmap.get("KeepPointBits") == null ? "3" : itemmap.get("KeepPointBits").toString();
                                            BigDecimal valuenum = new BigDecimal(value);
                                            BigDecimal roundnum = valuenum.setScale(Integer.parseInt(KeepPointBits), BigDecimal.ROUND_HALF_UP);
                                            //若修约后的结果=0，则修约到一位有效数字
                                            if (BigDecimal.ZERO.equals(roundnum)) {
                                                value = String.valueOf(SegmentFormula.ConvertData(valuenum.doubleValue()));
                                            } else {
                                                value = roundnum.toPlainString();
                                            }
                                            break;
                                        }
                                    }
                                }
                                WqDataTempdata.put(Value, value);
                                Number++;
                            }
                        }
                        //模板标题
                        WqDataTempdatatabulation.put("SampleTime", "监测时间");
                        WqDataTempdatatabulation.put("SegmentOrder", Long.valueOf("0"));
                        WqDataTempdatatabulation.put("BussinessCategoryCode", prop);
                        WqDataTempdatatabulation.put("businessCategory", bussinessCategory);
                        WqDataTempdatatabulation.put("ReportPerson", "");
                        WqDataTempdatatabulation.put("ReportID", ReportID);
                        WqDataTempdatatabulation.put("MonitorID", "采样编号");
                        WqDataTempdatatabulation.put("Remark", "备注");
                        WqDataTempdatatabulation.put("Status", Long.valueOf(0));

                        //模板里数据插入
                        WqDataTempdata.put("SampleTime", dataTime);
                        WqDataTempdata.put("SegmentOrder", rowIndex);
                        //WqDataTempdata.put("ReportDate",new Date());
                        WqDataTempdata.put("BussinessCategoryCode", prop);
                        WqDataTempdata.put("businessCategory", bussinessCategory);
                        WqDataTempdata.put("ReportPerson", "");
                        WqDataTempdata.put("MonitorID", "1");
                        WqDataTempdata.put("Status", Long.valueOf(0));
                        WqDataTempdata.put("ReportID", ReportID);
                        //备注 Remark
                        if (headerCellValue != null && headerCellValue.equals("备注")) {
                            if (cell != null) {
                                String value = String.valueOf(cell);//备注
                                WqDataTempdata.put("Remark", value);
                            }
                        }
                    }
                }
                WqDataTempdata.put("ID", UUID.randomUUID().toString());
                WqDataTempdatalist.add(WqDataTempdata);
                if (tabulation == 1) {
                    WqDataTempdatatabulation.put("ItemName", "");
                    WqDataTempdatatabulation.put("ID", UUID.randomUUID().toString());
                    WqDataTempdatalist.add(WqDataTempdatatabulation);
                    tabulation++;
                }

            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        //把处理过的数据存入临时表中
        if (WqDataTempdatalist != null && WqDataTempdatalist.size() > 0) {
            for (Map WqDataTempdatalistMap : WqDataTempdatalist) {
                Object sampleTime = WqDataTempdatalistMap.get("SampleTime");
                Object SegmentName = WqDataTempdatalistMap.get("SegmentName");
                if (sampleTime != null && !"--".equals(sampleTime)) {
                    if (SegmentName != null && !"".equals(String.valueOf(SegmentName))) {
                        manualMonitorDataMapper.insertWqDataTempdataMap(WqDataTempdatalistMap);

                    } else {
                        map.put("msg", "断面为空");
                        break;
                    }

                } else {
                    map.put("msg", "时间为空");
                    break;
                }

            }

        }
        //ReportID
        map.put("ReportID", ReportID);
        return map;
    }

    @Override
    public List<Map<String, Object>> wqDataTempdataReportID(Map<String, Object> map) {
        return manualMonitorDataMapper.wqDataTempdataReportID(map);
    }

    @Override
    public List<Map<String, Object>> importTemplateData(Map<String, Object> map) {
        //存放监测数据
        List<Map<String, Object>> listData = new ArrayList<>();
        SimpleDateFormat dfs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//时间格式
        //引入公共计算返回等级
        ItemCodeOverData itemCodeOverData = new ItemCodeOverData();
        //查询模板导入的数据表头
        Map<String, Object> importTemplateTitlemap = manualMonitorDataMapper.importTemplateTitle(map);
        //查询是否库中存在数据
        Map thereIsDataInTheLibrarymap = new HashMap();
        List<Map<String, Object>> segmentmaps = manualMonitorDataMapper.thereIsDataInTheLibrary(thereIsDataInTheLibrarymap);
        //查询因子名称
        List<Map<String, Object>> wqBasItemIDIsRiverEvalutelist = publicToolsMapper.wqBasItemIDIsRiverEvalutev2(thereIsDataInTheLibrarymap);

        Map wqcodbussinessitemsBankerSRoundingmap = new HashMap();
        List<Map<String, Object>> wqcodbussinessitemsBankerSRoundingUtilslist = publicToolsMapper.wqCodBussinessitemsbussinessCategoryCode(wqcodbussinessitemsBankerSRoundingmap);


        if (importTemplateTitlemap != null && importTemplateTitlemap.size() > 0) {
            //listData.add(importTemplateTitlemap);
            //BussinessCategoryCode 数据类型编码
            String bussinessCategoryCode = (String) importTemplateTitlemap.get("BussinessCategoryCode");
            //查询导入的监测数据列表
            List<Map<String, Object>> importTemplateDatamaps = manualMonitorDataMapper.importTemplateData(map);
            //判断监测数据是否存在
            if (importTemplateDatamaps != null && importTemplateDatamaps.size() > 0) {
                //循环处理监测数据
                for (Map<String, Object> datamap : importTemplateDatamaps) {
                    Map<String, Object> listdatamap = new HashMap<>();
                    String SegmentID = null; //断面id
                    String bussinessCategoryCodeData = null;
                    String monitorID = null;
                    String sampleDate = null;
                    //取单个map，因为导入数据的字段不确定多少不能写死取参数只能循环取库里有数据的参数
                    for (Map.Entry entry : datamap.entrySet()) {
                        //key值
                        String mapKey = (String) entry.getKey();
                        //value值
                        Object mapValue = entry.getValue();
                        if (mapValue != null && !"".equals(mapValue)) {
                            //判断是否存在断面id（在导入时能查询到的断面保存id）
                            if (mapKey.equals("SegmentID")) {
                                if (mapValue != null && !"".equals(mapValue)) {
                                    listdatamap.put("CheckSegmentName", "0");
                                    SegmentID = String.valueOf(mapValue);
                                    listdatamap.put("SegmentID", SegmentID);
                                } else {
                                    listdatamap.put("CheckSegmentName", "5");
                                }
                            } else {
                                listdatamap.put("CheckSegmentName", "5");
                                listdatamap.put("SegmentID", SegmentID);
                            }
                            //数据类型编码
                            if (mapKey.equals("BussinessCategoryCode")) {
                                if (mapValue != null && !"".equals(mapValue)) {
                                    bussinessCategoryCodeData = String.valueOf(mapValue);
                                }
                            }
                            if (mapKey.equals("MonitorID")) {
                                if (mapValue != null && !"".equals(mapValue)) {
                                    monitorID = String.valueOf(mapValue);
                                }
                            }
                            //监测时间
                            if (mapKey.equals("SampleTime")) {
                                if (mapValue != null && !"".equals(mapValue)) {
                                    sampleDate = String.valueOf(mapValue);
                                }
                            }
                            //查询导入的数据是否在正式库中存在 以断面id和数据类型和监测时间查询
                            if (SegmentID != null && sampleDate != null && monitorID != null && bussinessCategoryCodeData != null) {

                                if (segmentmaps != null && segmentmaps.size() > 0) {
                                    String finalSegmentID = SegmentID;
                                    String finalBussinessCategoryCodeData = bussinessCategoryCodeData;
                                    String finalMonitorID = monitorID;
                                    String finalSampleDate = sampleDate;
                                    List<Map<String, Object>> sunmapsLevel = segmentmaps.stream()
                                            .filter(item -> item.get("SegmentID").equals(finalSegmentID)
                                                    && item.get("BussinessCategoryCode").equals(finalBussinessCategoryCodeData)
                                                    && item.get("MonitorID").equals(finalMonitorID)
                                                    && item.get("sampleDate").equals(finalSampleDate))
                                            .collect(Collectors.toList());

                                    if (sunmapsLevel != null && sunmapsLevel.size() > 0) {
                                        listdatamap.put("CheckSegmentName", "7");
                                    }
                                }

                            }
                            //备注
                            if (mapKey.equals("Remark")) {

                            } else {
                                listdatamap.put("Remark", "");
                            }
                            //判断是否包含因子key
                            boolean itemvalue = mapKey.contains("value");
                            if (itemvalue) {
                                //Checkvalue ：0 正常 6 监测项不存在  10 该项在该业务中不存在 4 是否null 1 数据格式错误  2 超出范围 3 是否超标
                                //判断监测因子值不能为空和-1
                                if (mapValue != null && !"-1".equals(mapValue)) {
                                    //获取因子名称
                                    String itemName = (String) importTemplateTitlemap.get(mapKey);
                                    List<Map<String, Object>> itemNamelist = new ArrayList<>();
                                    List<Map<String, Object>> bussinessitemslist = new ArrayList<>();
                                    if (wqBasItemIDIsRiverEvalutelist != null && wqBasItemIDIsRiverEvalutelist.size() > 0) {
                                        //分组判断，stream流
                                        Map<String, List<Map<String, Object>>> sunmapsSegmentID =
                                                wqBasItemIDIsRiverEvalutelist.stream().collect(
                                                        Collectors.groupingBy(item -> item.get("CNName").toString())
                                                );
                                        itemNamelist = sunmapsSegmentID.get(itemName);
                                        Map<String, List<Map<String, Object>>> sunmapsSegmentIDs =
                                                wqcodbussinessitemsBankerSRoundingUtilslist.stream().collect(
                                                        Collectors.groupingBy(item -> item.get("ItemName").toString())
                                                );
                                        itemNamelist = sunmapsSegmentID.get(itemName);
                                        bussinessitemslist = sunmapsSegmentIDs.get(itemName);
                                    }
                                    String Itemid = null;
                                    if (itemNamelist != null && itemNamelist.size() > 0) {
                                        Itemid = (String) itemNamelist.get(0).get("ID");
                                    }
                                    String bussinessItemid = null;
                                    if (bussinessitemslist != null && bussinessitemslist.size() > 0) {
                                        bussinessItemid = (String) bussinessitemslist.get(0).get("ItemCode");
                                    }


                                    if (Itemid != null && !"".equals(Itemid)) {
                                        if (bussinessItemid != null && !"".equals(bussinessItemid)) {
                                            boolean notDigit = StringUtils.isNotDigit(String.valueOf(mapValue));
                                            if (notDigit) {
                                                boolean match = StringUtils.isMatch(String.valueOf(mapValue));
                                                String valueDatass = null;
                                                if (match) {
                                                    valueDatass = String.valueOf(mapValue);
                                                    if (mapValue != null && !"".equals(mapValue)) {
                                                        mapValue = StringUtils.validateCharacterString(String.valueOf(mapValue));
                                                        Double aDouble = Double.valueOf(String.valueOf(mapValue));
                                                        mapValue = aDouble / 2;
                                                        //判断是否科学计算法，如果是就进行转换
                                                        boolean scientificNotation = StringUtils.isScientificNotation(String.valueOf(mapValue));
                                                        if (scientificNotation) {
                                                            BigDecimal bigDecimal = new BigDecimal(String.valueOf(mapValue));
                                                            String effectiveValuesdatas = bigDecimal.toPlainString();
                                                            mapValue = effectiveValuesdatas;
                                                        } else {
                                                            mapValue = String.valueOf(mapValue);
                                                        }
                                                    }
                                                } else {
                                                    valueDatass = String.valueOf(mapValue);
                                                }
                                                //把监测数据转换类型
                                                Double DoubleValue = Double.valueOf(String.valueOf(mapValue));
                                                //[value 监测值, ItemCode 因子编码,itemName 因子名称 type 数据类型]
                                                String CheckvalueData = segmentFormula.ItemCodestate(DoubleValue, Itemid, "", bussinessCategoryCode);
                                                listdatamap.put("check" + mapKey, CheckvalueData);
                                                //进行判断因子的水质等级
                                                List<Map> levellist = new ArrayList<>();
                                                Map sectionStandardCalculation = new HashMap();
                                                sectionStandardCalculation.put("ItemCode", Itemid);
                                                sectionStandardCalculation.put("ID", SegmentID);
                                                sectionStandardCalculation.put("SegmentID", SegmentID);
                                                if (StringUtils.isNotEmpty(SegmentID)) {
                                                    levellist = publicToolsMapper.wqBasSegmenttargetlevelUtli(sectionStandardCalculation);
                                                }
                                                //断面标准计算
                                                if (levellist != null && levellist.size() > 0) {
                                                    Object targetLevel = levellist.get(0).get("TargetLevel");//目标级别
                                                    List<Map> list = publicToolsMapper.sectionStandardCalculation(sectionStandardCalculation);
                                                    //断面标准计算进行转换list
                                                    List<Standard> Standardlist = new ArrayList<>();
                                                    if (list != null && list.size() > 0) {
                                                        for (Map s : list) {
                                                            Standard standard = new Standard();//计算标准实体类
                                                            Object waterType = s.get("WaterType");//水体类型
                                                            Object StartDate = s.get("StartDate");//开始时间
                                                            Object EndDate = s.get("EndDate");//结束时间
                                                            Object ItemCodes = s.get("ItemCode");//监测项编码
                                                            Object Level = s.get("Level");//水质级别
                                                            Object CompareMethod = s.get("CompareMethod");//比对方法（0<= ，1>=，2>，3有或无，4未检出）
                                                            Object StandardValue = s.get("StandardValue");//标准值
                                                            Object Type = s.get("Type");//监测项目标准分类（常规、特殊）
                                                            Object StandardCategory = s.get("StandardCategory");//标准类别（河流/湖库/地下水）
                                                            //下面判读数据不为空进行数据处理到实体类里面
                                                            if (waterType != null && !"".equals(waterType)) {
                                                                standard.setWaterType(String.valueOf(waterType));
                                                            } else {
                                                                standard.setWaterType("");
                                                            }
                                                            if (StartDate != null && !"".equals(StartDate)) {
                                                                String StartDateString = String.valueOf(StartDate);
                                                                Date StartDateStringparse = null;
                                                                try {
                                                                    StartDateStringparse = dfs.parse(StartDateString);
                                                                } catch (ParseException e) {
                                                                    e.printStackTrace();
                                                                }
                                                                standard.setStartDate(StartDateStringparse);
                                                            }
                                                            if (EndDate != null && !"".equals(EndDate)) {
                                                                String EndDateString = String.valueOf(EndDate);
                                                                Date EndDateStringparse = null;
                                                                try {
                                                                    EndDateStringparse = dfs.parse(EndDateString);
                                                                } catch (ParseException e) {
                                                                    e.printStackTrace();
                                                                }
                                                                standard.setEndDate(EndDateStringparse);
                                                            }
                                                            if (ItemCodes != null && !"".equals(ItemCodes)) {
                                                                standard.setItemCode(String.valueOf(ItemCodes));
                                                            } else {
                                                                standard.setItemCode("");
                                                            }
                                                            if (Level != null && !"".equals(Level)) {
                                                                standard.setLevel(String.valueOf(Level));
                                                            } else {
                                                                standard.setLevel("");
                                                            }
                                                            if (StandardValue != null && !"".equals(StandardValue)) {
                                                                standard.setStandardValue(String.valueOf(StandardValue));
                                                            } else {
                                                                standard.setStandardValue("");
                                                            }
                                                            if (Type != null && !"".equals(Type)) {
                                                                standard.setType(String.valueOf(Type));
                                                            } else {
                                                                standard.setType("");
                                                            }
                                                            if (StandardCategory != null && !"".equals(StandardCategory)) {
                                                                standard.setStandardCategory(String.valueOf(StandardCategory));
                                                            } else {
                                                                standard.setStandardCategory("");
                                                            }
                                                            if (CompareMethod != null && !"".equals(CompareMethod)) {
                                                                standard.setCompareMethod(String.valueOf(CompareMethod));
                                                            } else {
                                                                standard.setCompareMethod("");
                                                            }
                                                            Standardlist.add(standard);
                                                        }
                                                    }
                                                    Integer integer = 0;
                                                    if (DoubleValue != null && Itemid != null && !"".equals(Itemid)) {
                                                        if (bussinessCategoryCodeData != null && "CBF8".equals(bussinessCategoryCodeData)) {
                                                            integer = itemCodeOverData.GetSingleType(DoubleValue, Standardlist, Itemid, String.valueOf(DoubleValue), 1);

                                                        } else {
                                                            integer = itemCodeOverData.GetSingleType(DoubleValue, Standardlist, Itemid, String.valueOf(DoubleValue), 0);
                                                        }
                                                    }
                                                    map.put("ItemName", itemName);//断面因子名称
                                                    if (Itemid.equals("15DE941F-A221-4D9C-8387-48B0E99F6E25")) {
                                                        if (DoubleValue >= Double.valueOf(String.valueOf(6)) && DoubleValue <= Double.valueOf(String.valueOf(9))) {

                                                        } else {
                                                            listdatamap.put("Check" + mapKey, "3");

                                                        }
                                                    } else {
                                                        if (integer != null) {
                                                            map.put("sectionLevel", integer);//断面计算出的级别
                                                        } else {
                                                            map.put("sectionLevel", 0);//断面计算出的级别
                                                            integer = 0;
                                                        }
                                                        listdatamap.put("Level" + mapKey, integer);
                                                        //判断目标级别不能为空
                                                        if (Standardlist != null && Standardlist.size() > 0 && targetLevel != null && !"".equals(targetLevel)) {
                                                            Integer targetLevelInteger = Integer.valueOf(String.valueOf(targetLevel));
                                                            int Level = targetLevelInteger;
                                                            if (integer > Level) {
                                                                listdatamap.put("Check" + mapKey, "3");
                                                            }
                                                        }
                                                    }
                                                } else {
                                                    listdatamap.put("Level" + mapKey, "");
                                                }

                                            } else {
                                                listdatamap.put("Check" + mapKey, "1");
                                                listdatamap.put("Level" + mapKey, "");
                                            }
                                        } else {
                                            listdatamap.put("Check" + mapKey, "10");
                                            listdatamap.put("Level" + mapKey, "");
                                        }
                                    } else {
                                        listdatamap.put("Check" + mapKey, "6");
                                        listdatamap.put("Level" + mapKey, "");
                                    }
                                } else {
                                    listdatamap.put("Check" + mapKey, "4");
                                    listdatamap.put("Level" + mapKey, "");
                                }
                            }
                            listdatamap.put(mapKey, mapValue);
                            //System.out.println(mapKey + ":" + mapValue);
                        }

                    }
                    listData.add(listdatamap);
                }
            }
        }
        return listData;
    }

    @Override
    public List<Map<String, Object>> importTemplateTitle(Map<String, Object> map) {
        //存放返回标题值
        List<Map<String, Object>> maplist = new ArrayList<>();
        //查询模板导入的数据表头
        Map<String, Object> importTemplateTitlemap = manualMonitorDataMapper.importTemplateTitle(map);
        //WqDataTempdata wqDataTempdata = WqDataTempdataMapper.importTemplateTitleName(map);
        if (importTemplateTitlemap != null && importTemplateTitlemap.size() > 0) {
            for (Map.Entry entry : importTemplateTitlemap.entrySet()) {
                Map mapData = new HashMap();
                Map CheckmapData = new HashMap();
                Map LevelCheckmapData = new HashMap();
                //key值
                String mapKey = (String) entry.getKey();
                //value值
                Object mapValue = entry.getValue();
                if (mapValue != null && !"".equals(mapValue)) {
                    //判断是否包含因子key
                    boolean itemvalue = mapKey.contains("value");
                    mapData.put("field", mapKey);//字段key
                    if (mapKey.equals("ID")) {
                        mapData.put("isShow", "0");//是否展示 0不展示 1展示
                    } else if (mapKey.equals("SegmentName")) {
                        mapData.put("isShow", "1");//是否展示 0不展示 1展示
                    } else if (mapKey.equals("SegmentID")) {
                        mapData.put("isShow", "0");//是否展示 0不展示 1展示
                    } else if (mapKey.equals("CheckSegmentName")) {
                        mapData.put("isShow", "0");//是否展示 0不展示 1展示
                    } else if (mapKey.equals("SampleTime")) {
                        mapData.put("isShow", "1");//是否展示 0不展示 1展示
                    } else if (mapKey.equals("CheckSampleTime")) {
                        mapData.put("isShow", "0");//是否展示 0不展示 1展示
                    } else if (mapKey.equals("MonitorID")) {
                        mapData.put("isShow", "0");//是否展示 0不展示 1展示
                    } else if (mapKey.equals("BussinessCategoryCode")) {
                        mapData.put("isShow", "0");//是否展示 0不展示 1展示
                    } else if (mapKey.equals("businessCategory")) {
                        mapData.put("isShow", "0");//是否展示 0不展示 1展示
                    } else if (mapKey.equals("SegmentOrder")) {
                        mapData.put("isShow", "0");//是否展示 0不展示 1展示
                    } else if (mapKey.equals("Status")) {
                        mapData.put("isShow", "0");//是否展示 0不展示 1展示
                    } else if (mapKey.equals("ReportDate")) {
                        mapData.put("isShow", "0");//是否展示 0不展示 1展示
                    } else if (mapKey.equals("ReportID")) {
                        mapData.put("isShow", "0");//是否展示 0不展示 1展示
                    } else if (mapKey.equals("HorizontalAzimuth")) {
                        mapData.put("isShow", "0");//是否展示 0不展示 1展示
                    } else if (mapKey.equals("VerticalAzimuth")) {
                        mapData.put("isShow", "0");//是否展示 0不展示 1展示
                    } else if (mapKey.equals("RiverName")) {
                        mapData.put("isShow", "0");//是否展示 0不展示 1展示
                    } else if (mapKey.equals("ReportPerson")) {
                        mapData.put("isShow", "0");//是否展示 0不展示 1展示
                    } else {
                        mapData.put("isShow", "1");//是否展示 0不展示 1展示
                    }
                    if (mapKey != null && "SegmentID".equals(mapKey)) {
                        mapData.put("title", "断面ID");
                    } else if (mapKey != null && "SegmentCode".equals(mapKey)) {
                        mapData.put("title", "断面编码");
                    } else {
                        mapData.put("title", mapValue);
                    }
                    //标题汉字
                    if (itemvalue) {
                        //因子状态
                        CheckmapData.put("field", "Check" + mapKey);//字段key
                        CheckmapData.put("isShow", "0");//是否展示 0不展示 1展示
                        CheckmapData.put("title", "Check" + mapKey); //标题汉字
                        //因子水质等级
                        LevelCheckmapData.put("field", "LevelCheck" + mapKey);//字段key
                        LevelCheckmapData.put("isShow", "0");//是否展示 0不展示 1展示
                        LevelCheckmapData.put("title", "LevelCheck" + mapKey); //标题汉字
                        maplist.add(CheckmapData);
                        maplist.add(LevelCheckmapData);

                    }

                    maplist.add(mapData);

                }

            }
        }

        return maplist;
    }

    @Override
    public int deleteBusTempdataByReportID(String reportId) {

        return manualMonitorDataMapper.deleteWqDataTempdataByReportID(reportId);
    }

    @Override
    public int importDataCover(Map map) {
        Object reportID1 = map.get("ReportID");
        Map<String, Object> maptemp = new HashMap<>();
        maptemp.put("ReportID", reportID1);
        maptemp.put("dataStateCode", "1");
        manualMonitorDataMapper.updateWqDataTempdataStateCode(maptemp);
        //查询需要处理的数据
        List<Map<String, Object>> wqDataTempdatalist = manualMonitorDataMapper.wqDataTempdataSegmentIDStatus(map);
        //先取对应断面的标题然后进行循环处理数据
        //获取时间
        String maxSampleDataTime = null;
        String minSampleDataTime = null;
        String BussinessCategoryCode = null;
        List<String> SampleDataTimelist = new ArrayList<>();
        List<String> SegmentIDlist = new ArrayList<>();
        List<Map<String, Object>> Segmentlist = new ArrayList<>();
        List<String> seid = new ArrayList<>();
        if (wqDataTempdatalist != null && wqDataTempdatalist.size() > 0) {
            for (Map<String, Object> data : wqDataTempdatalist) {
                Object SegmentID = data.get("SegmentID");
                boolean contains = seid.contains(SegmentID);
                if (contains) {
                } else {
                    seid.add(String.valueOf(SegmentID));
                }
            }
        }

        if (seid != null && seid.size() > 0) {
            // 定义异步任务
            CompletableFuture<Void> asyncTask = CompletableFuture.runAsync(() -> {
                this.importDataCoveryb(map);
                // 输出结果
                System.out.println("异步调用接口已完成");
            });
            busMonthlycumulativedataService.moonAssessTypeSegmen();
            return 0;
        } else {
            return 1;
        }

    }

    @Override
    public int importDataReserve(Map map) {
        return 0;
    }

    @Override
    public int importDataCoversyd(Map map) {
        //查询需要处理的数据
        List<Map<String, Object>> wqDataTempdatalist = manualMonitorDataMapper.wqDataTempdataSegmentIDStatus(map);
        //先取对应断面的标题然后进行循环处理数据
        List<String> seid = new ArrayList<>();
        if (wqDataTempdatalist != null && wqDataTempdatalist.size() > 0) {
            for (Map<String, Object> data : wqDataTempdatalist) {
                Object SegmentID = data.get("SegmentID");
                boolean contains = seid.contains(SegmentID);
                if (contains) {
                } else {
                    seid.add(String.valueOf(SegmentID));
                }
            }
        }
        if (seid != null && seid.size() > 0) {
// 定义异步任务
            CompletableFuture<Void> asyncTask = CompletableFuture.runAsync(() -> {
                // 模拟耗时操作
                //Thread.sleep(3000);
                this.importDataCoversydyb(map);
                // 输出结果
                System.out.println("异步调用接口已完成");
            });
            return 0;
        } else {
            return 1;
        }
    }

    @Override
    public List<Map<Object, Object>> getManualMonitorData(Map map) {
        //查询监测时间
        List<Map<Object, Object>> maunalDataManagementDataTimealllist = baseDrinkSegmentMapper.maunalDataManagementDataTimeall(map);
        //查询监测数据
        List<Map<Object, Object>> maunalDataManagementlist = baseDrinkSegmentMapper.maunalDataManagement(map);
        //源对象条件判断属性名 断面id
        String srcEqualProp = "SegmentID";
        //源对象待设置属性名   断面时间
        String srcSetProp = "SampleDate";
        /*因子id加 _Val 是监测因子数据*/
        long t1 = System.currentTimeMillis();
        //使用Java8自带的stream特性进行转换行转列
        List<Map<Object, Object>> resultList = maunalDataManagementDataTimealllist.stream().map(m1 -> {
            maunalDataManagementlist.stream()  //获取监测值的数据
                    .filter(m2 -> Objects.equals(m2.get(srcEqualProp), m1.get(srcEqualProp)) && Objects.equals(m2.get(srcSetProp), m1.get(srcSetProp)))
                    .forEach(m2 -> {
                        m1.put(m2.get("ItemCode") + "_Val", m2.get("OrginalValue"));//监测因子对应值
                        m1.put("SegmentID", m2.get("SegmentID"));//断面id
                        m1.put("SegmentName", m2.get("SegmentName"));//断面名称
                        m1.put("MonitorID", m2.get("MonitorID"));//
                        //m1.put("ReportID", m2.get("ReportID"));//
                        m1.put("ID", m2.get("valuatedataid"));//主键id
                        m1.put("SampleDate", m2.get("SampleDate"));//监测时间
                        m1.put("DrinkSourceName", m2.get("DrinkSourceName"));//水源地名称
                        m1.put("BussinessCategoryCode", m2.get("BussinessCategoryCode"));//监测值类型
                        m2.clear();
                    });
            return m1;
        }).collect(Collectors.toList());

        return resultList;
    }

    @Override
    public Integer deleteMaunalSegment(List<ManualParamVo> dvo) {
        int deleteint = 0;
        if (dvo != null && dvo.size() > 0) {
            List<String> segmentIDlist = new ArrayList<>();
            String beginTime = dvo.get(0).getSampleDate();
            //根据开始时间查询当前年份的最新累计时间
            String ksbeginTime = beginTime.substring(0, 7);//月份
            String substringyear = beginTime.substring(0, 4);//年份
            String endTime = DateUtils.dateFormat(new Date(), "yyyy-MM-dd HH:mm:ss");
            //循环取值(获取对应值进行删除)
            for (int i = 0; i < dvo.size(); i++) {
                ManualParamVo paramVo = dvo.get(i);
                String segmentID = paramVo.getSegmentId();//断面id
                String reportID = paramVo.getReportId();//上报批次ID
                String sampleDate = paramVo.getSampleDate();//监测时间
                String bussinessCategoryCode = paramVo.getBussinessCategoryCode();//监测值编码类型
                Map deleteMap = new HashMap();
                deleteMap.put("segmentID", segmentID);
                deleteMap.put("reportID", reportID);
                deleteMap.put("sampleDate", sampleDate);
                deleteMap.put("bussinessCategoryCode", bussinessCategoryCode);
                //监测值进行删除
                int datavale = baseDrinkSegmentMapper.deleteWqDataBasicsmonitordata(deleteMap);
                int datavales = baseDrinkSegmentMapper.deleteWqDataIntegrationmonitordata(deleteMap);
                //断面等级河超标级别删除
                int valuatedata = baseDrinkSegmentMapper.deletewqDataBasicevaluatedata(deleteMap);
                int valuatedatas = baseDrinkSegmentMapper.deletewqDataIntegrationevaluatedata(deleteMap);
                //断面累计数据删除
                if (bussinessCategoryCode != null && !"CBN3".equals(bussinessCategoryCode)) {
                    deleteMap.put("beginTime", ksbeginTime);
                    deleteMap.put("endTime", endTime);
                    deleteMap.put("YearData", substringyear);
                    int i1 = baseDrinkSegmentMapper.deletebasmonthlycumulativedata(deleteMap);
                    if (i1 != 0 && datavale != 0 && datavales != 0 && valuatedata != 0 && valuatedatas != 0) {
                        deleteint++;
                        boolean contains = segmentIDlist.contains(segmentID);
                        if (contains) {
                        } else {
                            segmentIDlist.add(segmentID);
                        }
                    }
                } else {
                    if (datavale != 0 && datavales != 0 && valuatedata != 0 && valuatedatas != 0) {
                        deleteint++;
                    }
                }


            }
        }

        return deleteint;
    }


    public int importDataCoveryb(Map map) {
        try {

            Object reportID1 = map.get("ReportID");
            //查询需要处理的数据
            List<Map<String, Object>> wqDataTempdatalist = manualMonitorDataMapper.wqDataTempdataSegmentIDStatus(map);
            Map<String, Object> dayas = new HashMap<>();
            //不参与计算的因子
//            List<Map<String, Object>> notcalculated_wateritemlist = manualMonitorDataMapper.notcalculated_wateritem(dayas);
            //先取对应断面的标题然后进行循环处理数据
            //获取时间
            String maxSampleDataTime = null;
            String minSampleDataTime = null;
            String BussinessCategoryCode = null;
            List<String> SampleDataTimelist = new ArrayList<>();
            List<String> SampleDataTimelistmon = new ArrayList<>();
            List<String> SegmentIDlist = new ArrayList<>();
            List<Map<String, Object>> Segmentlist = new ArrayList<>();
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            SimpleDateFormat dateFormats = new SimpleDateFormat("yyyy-MM-dd");
            SimpleDateFormat dateFormatsmon = new SimpleDateFormat("yyyy-MM");
            if (wqDataTempdatalist != null && wqDataTempdatalist.size() > 0) {
                for (Map<String, Object> data : wqDataTempdatalist) {
                    Map<String, Object> listmap = new HashMap<>();
                    Object remark = data.get("SegmentOrder");
                    if (remark != null && !"".equals(remark) && String.valueOf(remark).equals("0")) {
                        for (int i = 1; i <= 120; i++) {
                            Object o = data.get("value" + i);
                            if (o != null && !"".equals(o)) {
                                listmap.put("value" + i, o);
                                // listmap.put("pt"+i,i);
                            }

                            Segmentlist.add(listmap);
                        }

                    } else if (remark != null && !"".equals(remark) && !"0".equals(String.valueOf(remark))) {
                        Object SampleDataTime = data.get("SampleDataTimese");
                        Object SegmentID = data.get("SegmentID");
                        maxSampleDataTime = String.valueOf(data.get("maxSampleDataTime"));
                        minSampleDataTime = String.valueOf(data.get("minSampleDataTime"));
                        BussinessCategoryCode = String.valueOf(data.get("BussinessCategoryCode"));
                        boolean contains = SampleDataTimelist.contains(SampleDataTime);
                        Date parse1 = dateFormat.parse(String.valueOf(SampleDataTime));
                        String SampleDatmonse = dateFormatsmon.format(parse1);
                        boolean containss = SampleDataTimelistmon.contains(SampleDatmonse);
                        boolean sSegmentID = SegmentIDlist.contains(SegmentID);
                        if (contains) {
                        } else {
                            SampleDataTimelist.add(String.valueOf(SampleDataTime));
                        }
                        if (containss) {
                        } else {
                            SampleDataTimelistmon.add(String.valueOf(SampleDatmonse));
                        }
                        if (sSegmentID) {
                        } else {
                            if (SegmentID != null && !"".equals(SegmentID) && !"null".equals(SegmentID)) {
                                SegmentIDlist.add(String.valueOf(SegmentID));
                            }

                        }
                    }
                }
            }
            //

            if (BussinessCategoryCode != null && !"CBN3".equals(BussinessCategoryCode)) {
                if (SampleDataTimelist != null && SampleDataTimelist.size() > 0) {
                    for (String data : SampleDataTimelist) {
                        Date parse1 = dateFormat.parse(data);
                        String SampleDatmonse = dateFormatsmon.format(parse1);
                        Map<String, Object> datamaps = new HashMap<>();
                        datamaps.put("bussinessCategoryCode", BussinessCategoryCode);
                        datamaps.put("SampleDate", SampleDatmonse);
                        datamaps.put("segmentIds", SegmentIDlist);
//                        manualMonitorDataMapper.dataBasicsmonitordatasegmentID(datamaps);
//                        manualMonitorDataMapper.dataBasicevaluatedatasegmentID(datamaps);
//                        manualMonitorDataMapper.dataIntegrationmonitordatasegmentID(datamaps);
//                        manualMonitorDataMapper.dataIntegrationevaluatedatasegmentID(datamaps);


                    }
                }
            }

            DecimalFormat df = new DecimalFormat("#0.00");
            //查询手工监测数据是否存在数据
            Map<String, Object> segetbasicsmonitordatamap = new HashMap<>();
            //查询因子名称
            List<Map<String, Object>> wqBasItemIDIsRiverEvalutelist = publicToolsMapper.wqBasItemIDIsRiverEvalute(segetbasicsmonitordatamap);
            List<Map<String, Object>> sectionStandardCalculationlist = new ArrayList<>();
            //查询对应标准值
            List<Map> sectionStandardCalculationlists = publicToolsMapper.sectionStandardCalculation(segetbasicsmonitordatamap);
            if (sectionStandardCalculationlists != null && sectionStandardCalculationlists.size() > 0) {
                for (Map daya : sectionStandardCalculationlists) {
                    sectionStandardCalculationlist.add(daya);
                }

            }
            //查询对应因子修约位数
            List<Map<String, Object>> wqCodBussinessitemsbussinessCategoryCodelist = publicToolsMapper.wqCodBussinessitemsbussinessCategoryCode(segetbasicsmonitordatamap);

            List<String> seid = new ArrayList<>();
            if (wqDataTempdatalist != null && wqDataTempdatalist.size() > 0) {
                for (Map<String, Object> data : wqDataTempdatalist) {
                    Object segmentName = data.get("SegmentName");//断面名称
                    Object segmentID = data.get("SegmentID");//断面id
                    Object segmentCode = data.get("SegmentCode");//断面编码
                    Object sampleTime = data.get("SampleTime");//时间
                    Object SampleDataTime = data.get("SampleDataTime");//时间
                    Object segmentOrder = data.get("SegmentOrder");//数据顺序
                    Object reportID = data.get("ReportID");//上传编码
                    Object bussinessCategoryCode = data.get("BussinessCategoryCode");//数据类型编码
                    Object businessCategory = data.get("businessCategory");//数据类型
                    Object horizontalAzimuth = data.get("HorizontalAzimuth");//水平采样方位
                    Object monitorID = data.get("MonitorID");//采样编号 没有默认1
                    Object verticalAzimuth = data.get("VerticalAzimuth");//垂直采样方位
                    Object status = data.get("Status");////0保存入库/1删除不入库
                    Object remark = data.get("Remark");//备注  去等于备注的数据是对应断面标题
                    Object SegmentCategory = data.get("SegmentCategory");//断面类型
                    Object SegmentCategorys = data.get("SegmentCategorys");//断面类型 s
                    Object targetLevels = data.get("targetLevels");//断面类型 s
                    Object targetLevelNames = data.get("targetLevelNames");//断面类型 s
                    Object SampleDataTimesemon = data.get("SampleDataTimesemon");//断面类型 s
                    Object longitude = data.get("longitude");//经度 s
                    Object latitude = data.get("latitude");//纬度 s
                    Object dataSource = data.get("dataSource");//数据来源 s
                    List<String> itemp = new ArrayList<>();
                    if (segmentID != null && !"".equals(segmentID)) {
//                        List<Map<String, Object>> notcalculatedsegmentID=new ArrayList<>();
                        if (segmentOrder != null && !"0".equals(String.valueOf(segmentOrder))) {
                            if (Segmentlist != null && Segmentlist.size() > 0) {
                                int size = Segmentlist.size();
                                Map<String, Object> datalise = Segmentlist.get(0);
                                //for(Map<String, Object> datalise:Segmentlist){
                                for (int i = 1; i <= datalise.size(); i++) {
                                    BusWaterBasicsmonitordata WqDataBasicsmonitordata = new BusWaterBasicsmonitordata();
                                    //放入对应值
                                    if (targetLevels != null && !"".equals(targetLevels)) {
                                        WqDataBasicsmonitordata.setTargetLevel(Integer.valueOf(String.valueOf(targetLevels)));
                                    }
                                    if (targetLevelNames != null && !"".equals(targetLevelNames)) {
                                        WqDataBasicsmonitordata.setTargetLevelName(String.valueOf(targetLevelNames));
                                    }
                                    if (SegmentCategorys != null && !"".equals(SegmentCategorys)) {
                                        WqDataBasicsmonitordata.setSegmentCategory(String.valueOf(SegmentCategorys));
                                    }
                                    if (monitorID != null && !"".equals(monitorID)) {
                                        WqDataBasicsmonitordata.setMonitorid(String.valueOf(monitorID));
                                    } else {
                                        WqDataBasicsmonitordata.setMonitorid("1");

                                    }
                                    if (longitude != null && !"".equals(longitude)) {
                                        WqDataBasicsmonitordata.setLongitude(String.valueOf(longitude));
                                    }
                                    if (latitude != null && !"".equals(latitude)) {
                                        WqDataBasicsmonitordata.setLatitude(String.valueOf(latitude));
                                    }
                                    WqDataBasicsmonitordata.setIsdetect("0");
                                    if (SampleDataTime != null && !"".equals(SampleDataTime)) {
                                        Date parse = null;
                                        try {
                                            parse = dateFormat.parse(String.valueOf(SampleDataTime));
                                        } catch (ParseException e) {
                                            e.printStackTrace();
                                        }
                                        WqDataBasicsmonitordata.setSampledate(parse);
                                    }
                                    if (businessCategory != null && !"".equals(businessCategory)) {
                                        WqDataBasicsmonitordata.setBussinesscategory(String.valueOf(businessCategory));
                                    }
                                    if (bussinessCategoryCode != null && !"".equals(bussinessCategoryCode)) {
                                        WqDataBasicsmonitordata.setBussinesscategorycode(String.valueOf(bussinessCategoryCode));
                                    }
                                    if (horizontalAzimuth != null && !"".equals(horizontalAzimuth)) {
                                        WqDataBasicsmonitordata.setHorizontalazimuth(String.valueOf(horizontalAzimuth));
                                    } else {
                                        WqDataBasicsmonitordata.setHorizontalazimuth("");
                                    }
                                    if (verticalAzimuth != null && !"".equals(verticalAzimuth)) {
                                        WqDataBasicsmonitordata.setVerticalazimuth(String.valueOf(verticalAzimuth));
                                    }
                                    if (segmentName != null && !"".equals(segmentName)) {
                                        WqDataBasicsmonitordata.setSegmentname(String.valueOf(segmentName));
                                    }
                                    if (reportID != null && !"".equals(reportID)) {
                                        WqDataBasicsmonitordata.setReportid(String.valueOf(reportID));
                                    }
                                    if (segmentID != null && !"".equals(segmentID)) {
                                        WqDataBasicsmonitordata.setSegmentid(String.valueOf(segmentID));
                                    }
                                    if (segmentCode != null && !"".equals(segmentCode)) {
                                        WqDataBasicsmonitordata.setSegmentcode(String.valueOf(segmentCode));
                                    }

                                    //因子标题
                                    String itemCode = "";
                                    Object ItemName = datalise.get("value" + i);
                                    boolean contains = itemp.contains(ItemName);
                                    boolean containss = seid.contains(ItemName);
                                    if (contains) {
                                        System.out.println();
                                    } else {
                                        itemp.add(String.valueOf(ItemName));
                                        List<Map<String, Object>> sunmapsLevel = wqBasItemIDIsRiverEvalutelist.stream()
                                                .filter(item -> item.get("CNName").equals(ItemName)
                                                )
                                                .collect(Collectors.toList());
                                        if (sunmapsLevel != null && sunmapsLevel.size() > 0) {
                                            Object id = sunmapsLevel.get(0).get("ID");
                                            if (id != null && !"".equals(id)) {
                                                itemCode = String.valueOf(id);
                                            }
                                        }
                                        //上面获取对应因子编码
                                        if (itemCode != null && !"".equals(itemCode)) {
                                            WqDataBasicsmonitordata.setItemcode(itemCode);
                                        }
                                        if (ItemName != null && !"".equals(ItemName)) {
                                            WqDataBasicsmonitordata.setItemname(String.valueOf(ItemName));
                                        }
                                        //下面循环取参进行数据处理
                                        //获取对应因子值
                                        Object valueData = data.get("value" + i);
                                        if (valueData != null && !"".equals(valueData) && !"null".equals(valueData)) {
                                            boolean match = StringUtils.isMatch(String.valueOf(valueData));
                                            String valueDatass = null;
                                            if (match) {
                                                valueDatass = String.valueOf(valueData);
                                                if (valueData != null && !"".equals(valueData)) {
                                                    valueData = StringUtils.validateCharacterString(String.valueOf(valueData));
                                                    Double aDouble = Double.valueOf(String.valueOf(valueData));
                                                    valueData = aDouble / 2;
                                                    //判断是否科学计算法，如果是就进行转换
                                                    boolean scientificNotation = StringUtils.isScientificNotation(String.valueOf(valueData));
                                                    if (scientificNotation) {
                                                        BigDecimal bigDecimal = new BigDecimal(String.valueOf(valueData));
                                                        String effectiveValuesdatas = bigDecimal.toPlainString();
                                                        valueData = effectiveValuesdatas;
                                                    } else {
                                                        valueData = String.valueOf(valueData);
                                                    }
                                                }
                                            } else {
                                                valueDatass = String.valueOf(valueData);
                                            }

                                            if (valueDatass != null && !"".equals(valueDatass) && !"null".equals(valueDatass)) {
                                                WqDataBasicsmonitordata.setOrginalvalue(String.valueOf(valueDatass));
                                            } else {
                                                WqDataBasicsmonitordata.setOrginalvalue("-1");
                                            }
                                        }

                                        //下面进行数据计算和处理
                                        if (valueData != null && !"".equals(valueData) && !"-1".equals(valueData) && !"null".equals(valueData)) {

                                            //监测因子进行修约
                                            String xyvalueData = "";
                                            if (valueData != null && !"".equals(valueData) && !"-1".equals(valueData)) {
                                                String keepPointBitss = "3";
                                                boolean b = StringUtils.validateCharacter(String.valueOf(valueData));
                                                if (b) {
                                                    valueData = StringUtils.validateCharacterString(String.valueOf(valueData));
                                                } else {

                                                }
                                                if (wqCodBussinessitemsbussinessCategoryCodelist != null && wqCodBussinessitemsbussinessCategoryCodelist.size() > 0) {
                                                    String finalItemCode = itemCode;
                                                    List<Map<String, Object>> ItemCodeLevel = wqCodBussinessitemsbussinessCategoryCodelist.stream()
                                                            .filter(item -> item.get("BussinessCategoryCode").equals(bussinessCategoryCode)
                                                                    && item.get("ItemCode").equals(finalItemCode)
                                                            )
                                                            .collect(Collectors.toList());
                                                    if (ItemCodeLevel != null && ItemCodeLevel.size() > 0) {
                                                        Object keepPointBits = ItemCodeLevel.get(0).get("KeepPointBits");
                                                        if (keepPointBits != null && !"".equals(keepPointBits)) {
                                                            keepPointBitss = String.valueOf(keepPointBits);
                                                        }
                                                    }
                                                }
                                                BigDecimal number = new BigDecimal(String.valueOf(valueData));
                                                BigDecimal roundedNumber = number.setScale(Integer.parseInt(keepPointBitss), RoundingMode.HALF_UP); // 设置保留位数并进行四舍五入

                                                //xyvalueData = String.format(String.valueOf(roundedNumber));
                                                xyvalueData = String.valueOf(number);
                                                WqDataBasicsmonitordata.setEffectivevalue(number);
                                            } else {
                                                xyvalueData = "-1";
                                            }
                                            if (sectionStandardCalculationlist != null && sectionStandardCalculationlist.size() > 0) {
                                                //数据分组  SegmentCategory  ItemCode Level
                                                //分组判断，stream流 //断面类型
                                                List<Map<String, Object>> sunmapsitemCodelist = new ArrayList<>();
                                                Map<String, List<Map<String, Object>>> sunmapsSegmentCategory =
                                                        sectionStandardCalculationlist.stream().collect(
                                                                Collectors.groupingBy(item -> item.get("WaterType").toString())
                                                        );
                                                //SegmentCategorys 断面类型分组
                                                List<Map<String, Object>> sunmapsSegmentCategorylist = sunmapsSegmentCategory.get(String.valueOf(SegmentCategorys));
                                                //因子名称分组
                                                if (sunmapsSegmentCategorylist != null && sunmapsSegmentCategorylist.size() > 0) {
                                                    Map<String, List<Map<String, Object>>> sunmapsitemCode =
                                                            sunmapsSegmentCategorylist.stream().collect(
                                                                    Collectors.groupingBy(item -> item.get("ItemCode").toString())
                                                            );
                                                    sunmapsitemCodelist = sunmapsitemCode.get(itemCode);
                                                }
                                                //断面标准计算进行转换list
                                                List<Standard> Standardlist = new ArrayList<>();
                                                if (sunmapsitemCodelist != null && sunmapsitemCodelist.size() > 0) {
                                                    for (Map<String, Object> sunmapsitemCodelistdata : sunmapsitemCodelist) {
                                                        Object standardValue = sunmapsitemCodelistdata.get("StandardValue");//标准值
                                                        Object compareMethod = sunmapsitemCodelistdata.get("CompareMethod");//比对方法（0<= ，1>=，2>，3有或无，4未检出）
                                                        Object Level = sunmapsitemCodelistdata.get("Level");//级别
                                                        WqDataBasicsmonitordata.setStandardValue(String.valueOf(standardValue));
                                                        if (Level != null && !"".equals(Level)) {
                                                            if (String.valueOf(Level).equals("1")) {
                                                                if (compareMethod != null && !"".equals(compareMethod)) {
                                                                    if (compareMethod.equals("0")) {
                                                                        if (Double.valueOf(String.valueOf(xyvalueData)) > Double.valueOf(String.valueOf(standardValue))) {
                                                                            WqDataBasicsmonitordata.setIsoverstandard1("1");
                                                                            //超标倍数=（超标数据-标准）/标准 OverStandardTimes1
                                                                            Double v = (Double.valueOf(String.valueOf(xyvalueData)) - Double.valueOf(String.valueOf(standardValue))) / Double.valueOf(String.valueOf(standardValue));
                                                                            String format = df.format(v);
                                                                            WqDataBasicsmonitordata.setOverstandardtimes1(format);
                                                                        }
                                                                    }
                                                                    if (compareMethod.equals("1")) {
                                                                        if (Double.valueOf(String.valueOf(xyvalueData)) < Double.valueOf(String.valueOf(standardValue))) {
                                                                            //map.put("Isoverstandard2", "1");
                                                                            WqDataBasicsmonitordata.setIsoverstandard1("1");
                                                                        }
                                                                    }
                                                                    if (compareMethod.equals("2")) {
                                                                        if (Double.valueOf(String.valueOf(xyvalueData)) <= Double.valueOf(String.valueOf(standardValue))) {
                                                                            // map.put("Isoverstandard2", "1");
                                                                            WqDataBasicsmonitordata.setIsoverstandard1("1");
                                                                        }

                                                                    }
                                                                }
                                                            }
                                                            if (String.valueOf(Level).equals("2")) {
                                                                if (compareMethod != null && !"".equals(compareMethod)) {
                                                                    if (compareMethod.equals("0")) {
                                                                        if (Double.valueOf(String.valueOf(xyvalueData)) > Double.valueOf(String.valueOf(standardValue))) {
                                                                            WqDataBasicsmonitordata.setIsoverstandard2("1");
                                                                            //map.put("Isoverstandard2", "1");
                                                                            //超标倍数=（超标数据-标准）/标准 OverStandardTimes1
                                                                            Double v = (Double.valueOf(String.valueOf(xyvalueData)) - Double.valueOf(String.valueOf(standardValue))) / Double.valueOf(String.valueOf(standardValue));
                                                                            String format = df.format(v);
                                                                            WqDataBasicsmonitordata.setOverstandardtimes2(format);
                                                                            //map.put("Overstandardtimes2", format);
                                                                        }
                                                                    }
                                                                    if (compareMethod.equals("1")) {
                                                                        if (Double.valueOf(String.valueOf(xyvalueData)) < Double.valueOf(String.valueOf(standardValue))) {
                                                                            //map.put("Isoverstandard2", "1");
                                                                            WqDataBasicsmonitordata.setIsoverstandard2("1");
                                                                        }
                                                                    }
                                                                    if (compareMethod.equals("2")) {
                                                                        if (Double.valueOf(String.valueOf(xyvalueData)) <= Double.valueOf(String.valueOf(standardValue))) {
                                                                            // map.put("Isoverstandard2", "1");
                                                                            WqDataBasicsmonitordata.setIsoverstandard2("1");
                                                                        }

                                                                    }
                                                                }
                                                            }
                                                            if (String.valueOf(Level).equals("3")) {
                                                                if (compareMethod != null && !"".equals(compareMethod)) {
                                                                    if (compareMethod.equals("0")) {
                                                                        if (Double.valueOf(String.valueOf(xyvalueData)) > Double.valueOf(String.valueOf(standardValue))) {
                                                                            WqDataBasicsmonitordata.setIsoverstandard3("1");
                                                                            //超标倍数=（超标数据-标准）/标准 OverStandardTimes1
                                                                            Double v = (Double.valueOf(String.valueOf(xyvalueData)) - Double.valueOf(String.valueOf(standardValue))) / Double.valueOf(String.valueOf(standardValue));
                                                                            String format = df.format(v);
                                                                            WqDataBasicsmonitordata.setOverstandardtimes3(format);
                                                                        }
                                                                    }
                                                                    if (compareMethod.equals("1")) {
                                                                        if (Double.valueOf(String.valueOf(xyvalueData)) < Double.valueOf(String.valueOf(standardValue))) {
                                                                            //map.put("Isoverstandard2", "1");
                                                                            WqDataBasicsmonitordata.setIsoverstandard3("1");
                                                                        }
                                                                    }
                                                                    if (compareMethod.equals("2")) {
                                                                        if (Double.valueOf(String.valueOf(xyvalueData)) <= Double.valueOf(String.valueOf(standardValue))) {
                                                                            // map.put("Isoverstandard2", "1");
                                                                            WqDataBasicsmonitordata.setIsoverstandard3("1");
                                                                        }

                                                                    }
                                                                }
                                                            }
                                                            if (String.valueOf(Level).equals("4")) {
                                                                if (compareMethod != null && !"".equals(compareMethod)) {
                                                                    if (compareMethod.equals("0")) {
                                                                        if (Double.valueOf(String.valueOf(xyvalueData)) > Double.valueOf(String.valueOf(standardValue))) {
                                                                            WqDataBasicsmonitordata.setIsoverstandard4("1");
                                                                            //超标倍数=（超标数据-标准）/标准 OverStandardTimes1
                                                                            Double v = (Double.valueOf(String.valueOf(xyvalueData)) - Double.valueOf(String.valueOf(standardValue))) / Double.valueOf(String.valueOf(standardValue));
                                                                            String format = df.format(v);
                                                                            WqDataBasicsmonitordata.setOverstandardtimes4(format);
                                                                        }
                                                                    }
                                                                    if (compareMethod.equals("1")) {
                                                                        if (Double.valueOf(String.valueOf(xyvalueData)) < Double.valueOf(String.valueOf(standardValue))) {
                                                                            //map.put("Isoverstandard2", "1");
                                                                            WqDataBasicsmonitordata.setIsoverstandard4("1");
                                                                        }
                                                                    }
                                                                    if (compareMethod.equals("2")) {
                                                                        if (Double.valueOf(String.valueOf(xyvalueData)) <= Double.valueOf(String.valueOf(standardValue))) {
                                                                            // map.put("Isoverstandard2", "1");
                                                                            WqDataBasicsmonitordata.setIsoverstandard4("1");
                                                                        }

                                                                    }
                                                                }
                                                            }
                                                            if (String.valueOf(Level).equals("5")) {
                                                                if (compareMethod != null && !"".equals(compareMethod)) {
                                                                    if (compareMethod.equals("0")) {
                                                                        if (Double.valueOf(String.valueOf(xyvalueData)) > Double.valueOf(String.valueOf(standardValue))) {
                                                                            WqDataBasicsmonitordata.setIsoverstandard5("1");
                                                                            //超标倍数=（超标数据-标准）/标准 OverStandardTimes1
                                                                            Double v = (Double.valueOf(String.valueOf(xyvalueData)) - Double.valueOf(String.valueOf(standardValue))) / Double.valueOf(String.valueOf(standardValue));
                                                                            String format = df.format(v);
                                                                            WqDataBasicsmonitordata.setOverstandardtimes5(format);
                                                                        }
                                                                    }
                                                                    if (compareMethod.equals("1")) {
                                                                        if (Double.valueOf(String.valueOf(xyvalueData)) < Double.valueOf(String.valueOf(standardValue))) {
                                                                            WqDataBasicsmonitordata.setIsoverstandard5("1");
                                                                        }
                                                                    }
                                                                    if (compareMethod.equals("2")) {
                                                                        if (Double.valueOf(String.valueOf(xyvalueData)) <= Double.valueOf(String.valueOf(standardValue))) {
                                                                            WqDataBasicsmonitordata.setIsoverstandard5("1");
                                                                        }

                                                                    }
                                                                }
                                                            }
                                                        }


                                                    }
                                                }
                                                if (sunmapsitemCodelist != null && sunmapsitemCodelist.size() > 0) {
                                                    for (Map s : sunmapsitemCodelist) {
                                                        Standard Standard = new Standard();//计算标准实体类
                                                        Object waterType = s.get("WaterType");//水体类型
                                                        Object StartDate = s.get("StartDate");//开始时间
                                                        Object EndDate = s.get("EndDate");//结束时间
                                                        Object ItemCodes = s.get("ItemCode");//监测项编码
                                                        Object Level = s.get("Level");//水质级别
                                                        Object CompareMethod = s.get("CompareMethod");//比对方法（0<= ，1>=，2>，3有或无，4未检出）
                                                        Object StandardValue = s.get("StandardValue");//标准值
                                                        Object Type = s.get("Type");//监测项目标准分类（常规、特殊）
                                                        Object StandardCategory = s.get("StandardCategory");//标准类别（河流/湖库/地下水）
                                                        //下面判读数据不为空进行数据处理到实体类里面
                                                        if (waterType != null && !"".equals(waterType)) {
                                                            Standard.setWaterType(String.valueOf(waterType));
                                                        } else {
                                                            Standard.setWaterType("");
                                                        }
                                                        if (StartDate != null && !"".equals(StartDate)) {
                                                            String StartDateString = String.valueOf(StartDate);
                                                            Date StartDateStringparse = null;
                                                            try {
                                                                StartDateStringparse = dateFormat.parse(StartDateString);
                                                            } catch (ParseException e) {
                                                                e.printStackTrace();
                                                            }
                                                            Standard.setStartDate(StartDateStringparse);
                                                        }
                                                        if (EndDate != null && !"".equals(EndDate)) {
                                                            String EndDateString = String.valueOf(EndDate);
                                                            Date EndDateStringparse = null;
                                                            try {
                                                                EndDateStringparse = dateFormat.parse(EndDateString);
                                                            } catch (ParseException e) {
                                                                e.printStackTrace();
                                                            }
                                                            Standard.setEndDate(EndDateStringparse);
                                                        }
                                                        if (ItemCodes != null && !"".equals(ItemCodes)) {
                                                            Standard.setItemCode(String.valueOf(ItemCodes));
                                                        } else {
                                                            Standard.setItemCode("");
                                                        }
                                                        if (Level != null && !"".equals(Level)) {
                                                            Standard.setLevel(String.valueOf(Level));
                                                        } else {
                                                            Standard.setLevel("");
                                                        }
                                                        if (StandardValue != null && !"".equals(StandardValue)) {
                                                            Standard.setStandardValue(String.valueOf(StandardValue));
                                                        } else {
                                                            Standard.setStandardValue("");
                                                        }
                                                        if (Type != null && !"".equals(Type)) {
                                                            Standard.setType(String.valueOf(Type));
                                                        } else {
                                                            Standard.setType("");
                                                        }
                                                        if (StandardCategory != null && !"".equals(StandardCategory)) {
                                                            Standard.setStandardCategory(String.valueOf(StandardCategory));
                                                        } else {
                                                            Standard.setStandardCategory("");
                                                        }
                                                        if (CompareMethod != null && !"".equals(CompareMethod)) {
                                                            Standard.setCompareMethod(String.valueOf(CompareMethod));
                                                        } else {
                                                            Standard.setCompareMethod("");
                                                        }
                                                        Standardlist.add(Standard);
                                                    }
                                                }
                                                if (itemCode != null && "15DE941F-A221-4D9C-8387-48B0E99F6E25".equals(itemCode)) {
                                                    WqDataBasicsmonitordata.setStandardValue(String.valueOf("6~9"));
                                                    if (Double.valueOf(String.valueOf(xyvalueData)) >= Double.valueOf(String.valueOf(6)) && Double.valueOf(String.valueOf(xyvalueData)) <= Double.valueOf(String.valueOf(9))) {
                                                        WqDataBasicsmonitordata.setIsoverstandard1("0");
                                                        WqDataBasicsmonitordata.setIsoverstandard2("0");
                                                        WqDataBasicsmonitordata.setIsoverstandard3("0");
                                                        WqDataBasicsmonitordata.setIsoverstandard4("0");
                                                        WqDataBasicsmonitordata.setIsoverstandard5("0");
                                                    } else {
                                                        WqDataBasicsmonitordata.setIsoverstandard1("1");
                                                        WqDataBasicsmonitordata.setIsoverstandard2("1");
                                                        WqDataBasicsmonitordata.setIsoverstandard3("1");
                                                        WqDataBasicsmonitordata.setIsoverstandard4("1");
                                                        WqDataBasicsmonitordata.setIsoverstandard5("1");
                                                    }
                                                }

                                                //计算水质级别
                                                if (xyvalueData != null && !"".equals(xyvalueData) && !"-1".equals(xyvalueData)) {
                                                    Integer integer = ItemCodeOverData.GetSingleType(Double.valueOf(String.valueOf(xyvalueData)), Standardlist, String.valueOf(itemCode), String.valueOf(xyvalueData), Integer.valueOf(String.valueOf(SegmentCategory)));
                                                    //获取到对应级别之后进行转换成水质级别类型名称，返回级别如果不为空 级别*10（因为转换数据需要这种）
                                                    if (integer != null) {
                                                        integer = integer;//断面计算出的级别
                                                    } else {
                                                        //断面计算出的级别
                                                        integer = 0;
                                                    }
                                                    //转换水质级别名称
                                                    String LevelName = WaterLevelCompute.GetLevelName(integer, "");
                                                    WqDataBasicsmonitordata.setQualityLevelName(LevelName);
                                                    WqDataBasicsmonitordata.setQualitylevel(String.valueOf(integer));
                                                }
                                                if (targetLevels != null && !"".equals(targetLevels)) {
                                                    Integer integer1 = Integer.valueOf(String.valueOf(targetLevels));
                                                    if (integer1 == 1) {
                                                        if (WqDataBasicsmonitordata.getIsoverstandard1() != null && !"".equals(WqDataBasicsmonitordata.getIsoverstandard1())) {
                                                            WqDataBasicsmonitordata.setIsOverStandard(String.valueOf(WqDataBasicsmonitordata.getIsoverstandard1()));
                                                        }
                                                        if (WqDataBasicsmonitordata.getOverstandardtimes1() != null && !"".equals(WqDataBasicsmonitordata.getOverstandardtimes1())) {
                                                            WqDataBasicsmonitordata.setOverStandardTimes(String.valueOf(WqDataBasicsmonitordata.getOverstandardtimes1()));
                                                        }
                                                    }
                                                    if (integer1 == 2) {
                                                        if (WqDataBasicsmonitordata.getIsoverstandard2() != null && !"".equals(WqDataBasicsmonitordata.getIsoverstandard2())) {
                                                            WqDataBasicsmonitordata.setIsOverStandard(String.valueOf(WqDataBasicsmonitordata.getIsoverstandard2()));
                                                        }
                                                        if (WqDataBasicsmonitordata.getOverstandardtimes2() != null && !"".equals(WqDataBasicsmonitordata.getOverstandardtimes2())) {
                                                            WqDataBasicsmonitordata.setOverStandardTimes(String.valueOf(WqDataBasicsmonitordata.getOverstandardtimes2()));
                                                        }
                                                    }
                                                    if (integer1 == 3) {
                                                        if (WqDataBasicsmonitordata.getIsoverstandard3() != null && !"".equals(WqDataBasicsmonitordata.getIsoverstandard3())) {
                                                            WqDataBasicsmonitordata.setIsOverStandard(String.valueOf(WqDataBasicsmonitordata.getIsoverstandard3()));
                                                        }
                                                        if (WqDataBasicsmonitordata.getOverstandardtimes3() != null && !"".equals(WqDataBasicsmonitordata.getOverstandardtimes3())) {
                                                            WqDataBasicsmonitordata.setOverStandardTimes(String.valueOf(WqDataBasicsmonitordata.getOverstandardtimes3()));
                                                        }
                                                    }
                                                    if (integer1 == 4) {
                                                        if (WqDataBasicsmonitordata.getIsoverstandard4() != null && !"".equals(WqDataBasicsmonitordata.getIsoverstandard4())) {
                                                            WqDataBasicsmonitordata.setIsOverStandard(String.valueOf(WqDataBasicsmonitordata.getIsoverstandard4()));
                                                        }
                                                        if (WqDataBasicsmonitordata.getOverstandardtimes4() != null && !"".equals(WqDataBasicsmonitordata.getOverstandardtimes4())) {
                                                            WqDataBasicsmonitordata.setOverStandardTimes(String.valueOf(WqDataBasicsmonitordata.getOverstandardtimes4()));
                                                        }
                                                    }
                                                    if (integer1 == 5) {
                                                        if (WqDataBasicsmonitordata.getIsoverstandard5() != null && !"".equals(WqDataBasicsmonitordata.getIsoverstandard5())) {
                                                            WqDataBasicsmonitordata.setIsOverStandard(String.valueOf(WqDataBasicsmonitordata.getIsoverstandard5()));
                                                        }
                                                        if (WqDataBasicsmonitordata.getOverstandardtimes5() != null && !"".equals(WqDataBasicsmonitordata.getOverstandardtimes5())) {
                                                            WqDataBasicsmonitordata.setOverStandardTimes(String.valueOf(WqDataBasicsmonitordata.getOverstandardtimes5()));
                                                        }
                                                    }
                                                }

                                            }
                                        }
                                        if(StringUtils.isNotNull(dataSource)){
                                            WqDataBasicsmonitordata.setDatasource(String.valueOf(dataSource));
                                        }else{
                                            WqDataBasicsmonitordata.setDatasource("");
                                        }
                                        //判断手工数据是否存在
                                        Map<String, Object> getbasicsmonitordatamap = new HashMap<>();
                                        getbasicsmonitordatamap.put("SegmentID", segmentID);
                                        getbasicsmonitordatamap.put("BussinessCategoryCode", bussinessCategoryCode);
                                        getbasicsmonitordatamap.put("ItemCode", itemCode);

                                        if (bussinessCategoryCode != null && "CBN3".equals(bussinessCategoryCode)) {
                                            getbasicsmonitordatamap.put("HorizontalAzimuth", horizontalAzimuth);
                                            getbasicsmonitordatamap.put("SampleDate", SampleDataTime);
                                        } else {
                                            getbasicsmonitordatamap.put("SampleDatemon", DateUtils.dateFormat(DateUtils.dateTime("yyyy-MM-dd HH:mm:ss", String.valueOf(SampleDataTime)),"yyyy-MM"));
                                        }
                                        List<Map<String, Object>> getbasicsmonitordata = busBasicsmonitordataMapper.getbasicsmonitordata(getbasicsmonitordatamap);

                                        if (getbasicsmonitordata != null && getbasicsmonitordata.size() > 0) {
                                            String finalItemCode1 = itemCode;
                                            List<Map<String, Object>> getbasicsmonitordatalist = getbasicsmonitordata.stream()
                                                    .filter(item -> String.valueOf(item.get("SegmentID")).equals(String.valueOf(segmentID))
                                                            && String.valueOf(item.get("BussinessCategoryCode")).equals(String.valueOf(bussinessCategoryCode))
                                                            && String.valueOf(item.get("ItemCode")).equals(finalItemCode1)
                                                            && String.valueOf(item.get("SampleDataTimes")).equals(String.valueOf(SampleDataTime))
//                                                            && String.valueOf(item.get("HorizontalAzimuth")).equals(String.valueOf(horizontalAzimuth))
                                                            && String.valueOf(item.get("datasource")).equals(WqDataBasicsmonitordata.getDatasource())
                                                    )
                                                    .collect(Collectors.toList());
                                            int getbasicsmonitordatalistsize = getbasicsmonitordatalist.size();
                                            //如果存在数据就更新对应id的数据
                                            String ids = "";
                                            String isOverStandardses = WqDataBasicsmonitordata.getIsOverStandard();
                                            if (isOverStandardses != null && !"".equals(isOverStandardses)) {

                                            } else {
                                                WqDataBasicsmonitordata.setIsOverStandard("0");
                                            }
                                            if (getbasicsmonitordatalist != null && getbasicsmonitordatalist.size() > 0) {
                                                for (Map<String, Object> getbasicsmonitordatalistdata : getbasicsmonitordatalist) {
                                                    Object id = getbasicsmonitordatalistdata.get("ID");
                                                    ids = String.valueOf(id);
                                                }
                                            }
                                            if (ids != null && !"".equals(ids)) {
                                                WqDataBasicsmonitordata.setId(ids);
                                                int i1 = busBasicsmonitordataMapper.updateWq_data_basicsmonitordata(WqDataBasicsmonitordata);
                                            } else {
                                                System.out.println(WqDataBasicsmonitordata.toString());
                                                int i1 = busBasicsmonitordataMapper.insertWq_data_basicsmonitordata(WqDataBasicsmonitordata);
                                            }

                                        } else {
                                            int i1 = busBasicsmonitordataMapper.insertWq_data_basicsmonitordata(WqDataBasicsmonitordata);

                                        }
                                    }
                                }
                            }
                        }
                    }


                }
            }
            int getbasicevaluatedata = this.getbasicevaluatedata(BussinessCategoryCode, SegmentIDlist, minSampleDataTime, maxSampleDataTime);

            Map<String, Object> getintegrationmonitordatadatamap = new HashMap<>();
            Map<String, Object> getintegrationmonitordatamap = new HashMap<>();
            getintegrationmonitordatadatamap.put("SegmentIDs", SegmentIDlist);
            Date parse1mx = dateFormat.parse(maxSampleDataTime);
            String SampleDatmonsemx = dateFormatsmon.format(parse1mx);
            Date parse1mi = dateFormat.parse(minSampleDataTime);
            String SampleDatmonsemi = dateFormatsmon.format(parse1mi);
            getintegrationmonitordatadatamap.put("jsSampleTime", SampleDatmonsemx);
            getintegrationmonitordatadatamap.put("ksSampleTime", SampleDatmonsemi);
            getintegrationmonitordatadatamap.put("BussinessCategoryCode", BussinessCategoryCode);
            List<Map<String, Object>> getintegrationmonitordatadata = busIntegrationmonitordataMapper.getintegrationmonitordatadatav2(getintegrationmonitordatadatamap);

            List<Map<String, Object>> getintegrationmonitordata = busIntegrationmonitordataMapper.getintegrationmonitordatav2(getintegrationmonitordatadatamap);

            if (SampleDataTimelistmon != null && SampleDataTimelistmon.size() > 0) {
                for (String dateTime : SampleDataTimelistmon) {
                    // Date parse1 = dateFormat.parse(dateTime);
                    String SampleDatmonse = dateTime;
                    if (SegmentIDlist != null && SegmentIDlist.size() > 0) {
                        for (String dateid : SegmentIDlist) {
                            if ("C38191BB-E701-4129-9077-35E7EE23F876".equals(dateid)) {
                                System.out.println("");
                            }
                            if (Segmentlist != null && Segmentlist.size() > 0) {
                                if (getintegrationmonitordatadata != null && getintegrationmonitordatadata.size() > 0) {
                                    String finalBussinessCategoryCode = BussinessCategoryCode;

                                    List<Map<String, Object>> sunmapsLevel = getintegrationmonitordatadata.stream()
                                            .filter(item -> item.get("ID").equals(dateid)
                                                    && item.get("SampleDatmonse").equals(SampleDatmonse)
                                                    && item.get("BussinessCategoryCode").equals(finalBussinessCategoryCode))
                                            .collect(Collectors.toList());
                                    //按照数据来源分组
                                    List<String> datasourcesList = new ArrayList<>();
                                    for (Map<String, Object> data : sunmapsLevel) {
                                      String dataSources=String.valueOf( data.get("dataSources"));
                                      if(!datasourcesList.contains(dataSources)){
                                          datasourcesList.add(dataSources);
                                      }
                                    }
                                    for (String datasources : datasourcesList) {
                                        List<Map<String, Object>> sunmapsLevelone = getintegrationmonitordatadata.stream()
                                                .filter(item -> String.valueOf(item.get("dataSources")).equals(datasources))
                                                .collect(Collectors.toList());

                                        if (sunmapsLevelone != null && sunmapsLevelone.size() > 0) {
                                            for (Map<String, Object> data : sunmapsLevelone) {
                                                BusIntegrationmonitordata WqDataIntegrationmonitordata = new BusIntegrationmonitordata();
                                                Object id = data.get("ID");//断面id
                                                Object Remark1 = data.get("Remark1");//
                                                if (Remark1 != null && !"".equals(Remark1)) {
                                                    WqDataIntegrationmonitordata.setRemark1(String.valueOf(Remark1));
                                                }
                                                //断面类型 0地表水 1地下水
                                                Object segmentCategory = data.get("segmentCategory");
                                                //断面类型  0河流/1湖库/2地下水
                                                Object SegmentCategorys = data.get("segmentCategorys");
                                                Object segmentName = data.get("SegmentName");//断面名称
                                                Object segmentCode = data.get("SegmentCode");//断面编码
                                                Object reportID = data.get("ReportID");//上报批次ID
                                                Object horizontalAzimuth = data.get("HorizontalAzimuth");//
                                                Object verticalAzimuth = data.get("VerticalAzimuth");
                                                Object tideType = data.get("TideType");
                                                //断面数据类型编码
                                                Object bussinessCategoryCode = data.get("BussinessCategoryCode");
                                                //断面数据类型
                                                Object bussinessCategory = data.get("BussinessCategory");
                                                Object monitorID = data.get("MonitorID");//默认1
                                                Object isDelete = data.get("IsDelete");//
                                                Object remark = data.get("Remark");//备注
                                                //Object effectiveValue = data.get("EffectiveValue");//均值
                                                Object itemName = data.get("ItemName");//因子名称
                                                Object itemCode = data.get("ItemCode");//因子编码
                                                Object sampleDates = data.get("SampleDates");//时间未格式化
                                                Object SampleDatese = data.get("SampleDatese");//时间未格式化SampleDatese
                                                Object sampleDate = data.get("SampleDate");//格式化后时间
                                                Object targetLevel = data.get("TargetLevel");//目标级别
                                                Object targetLevelName = data.get("TargetLevelName");//目标级别
                                                Object OrginalValue = data.get("OrginalValue");//原始值
                                                Object segmentCategorys = data.get("segmentCategorys");//断面类型 s
                                                Object avgEffectiveValue = data.get("avgEffectiveValue");//均值不修约
                                                Object dataSource= data.get("dataSource");//数据来源

                                                String effectiveValue = null;
                                                //监测因子进行修约
                                                if (avgEffectiveValue != null && !"".equals(avgEffectiveValue)) {
                                                    String xyvalueData = "";
                                                    String ysxyvalueData = "";
                                                    if (avgEffectiveValue != null && !"".equals(avgEffectiveValue) && !"-1".equals(avgEffectiveValue) && Double.valueOf(String.valueOf(avgEffectiveValue)) != -1) {
                                                        String keepPointBitss = "3";
                                                        Integer keepPointBitssys = 3;
                                                        boolean b = StringUtils.validateCharacter(String.valueOf(avgEffectiveValue));
                                                        if (b) {
                                                            avgEffectiveValue = StringUtils.validateCharacterString(String.valueOf(avgEffectiveValue));
                                                        } else {

                                                        }
                                                        if (wqCodBussinessitemsbussinessCategoryCodelist != null && wqCodBussinessitemsbussinessCategoryCodelist.size() > 0) {
                                                            List<Map<String, Object>> ItemCodeLevel = wqCodBussinessitemsbussinessCategoryCodelist.stream()
                                                                    .filter(item -> item.get("BussinessCategoryCode").equals(bussinessCategoryCode)
                                                                            && item.get("ItemCode").equals(itemCode)
                                                                    )
                                                                    .collect(Collectors.toList());
                                                            if (ItemCodeLevel != null && ItemCodeLevel.size() > 0) {
                                                                Object keepPointBits = ItemCodeLevel.get(0).get("KeepPointBits");
                                                                if (keepPointBits != null && !"".equals(keepPointBits)) {
                                                                    keepPointBitss = String.valueOf(keepPointBits);
                                                                    keepPointBitssys = Integer.valueOf(String.valueOf(keepPointBits)) + 5;
                                                                }
                                                            }
                                                        }
                                                        String avgdata = BankerSRoundingUtils.sciCal(Double.valueOf(String.valueOf(avgEffectiveValue)), Integer.valueOf(keepPointBitss));
                                                        String ysavgdata = BankerSRoundingUtils.sciCal(Double.valueOf(String.valueOf(avgEffectiveValue)), keepPointBitssys);
                                                        BigDecimal bd = new BigDecimal(String.valueOf(ysavgdata));
                                                        ysavgdata = bd.stripTrailingZeros().toPlainString();

                                                        if (avgdata != null && !"".equals(avgdata)) {
                                                            Double aDouble = Double.valueOf(avgdata);
                                                            if (aDouble <= 0) {
//转换后的监测值进行判读是否有小数位
                                                                boolean contains = avgdata.contains(".");
                                                                if (contains) {
                                                                    Double aDouble1 = SegmentFormula.ConvertData(Double.valueOf(String.valueOf(avgEffectiveValue)));//存在有小数才进行截取有效值
//四舍 保留最后获取小数点后的位数
                                                                    String datav = BankerSRoundingUtils.sciCal(aDouble1, String.valueOf(aDouble1).length());
                                                                    effectiveValue = datav;
                                                                }
                                                            } else {

                                                                effectiveValue = String.valueOf(avgdata);
                                                            }
                                                        }
                                                        ysxyvalueData = String.valueOf(ysavgdata);
                                                    } else {
                                                        xyvalueData = "-1";
                                                        ysxyvalueData = "-1";
                                                    }
                                                    if (ysxyvalueData != null && !"".equals(ysxyvalueData)) {
                                                        WqDataIntegrationmonitordata.setOrginalvalue(ysxyvalueData);
                                                    }
                                                }
                                                if (targetLevel != null && !"".equals(targetLevel)) {
                                                    WqDataIntegrationmonitordata.setTargetLevel(Integer.valueOf(String.valueOf(targetLevel)));
                                                }
                                                if (targetLevelName != null && !"".equals(targetLevelName)) {
                                                    WqDataIntegrationmonitordata.setTargetLevelName(String.valueOf(targetLevelName));
                                                }
                                                if (segmentCategorys != null && !"".equals(segmentCategorys)) {
                                                    WqDataIntegrationmonitordata.setSegmentCategory(String.valueOf(segmentCategorys));
                                                }
                                                //DataSource
                                                if (SampleDatese != null && !"".equals(SampleDatese)) {
                                                    Date parse = null;
                                                    try {
                                                        parse = dateFormat.parse(String.valueOf(SampleDatese));
                                                    } catch (ParseException e) {
                                                        e.printStackTrace();
                                                    }
                                                    WqDataIntegrationmonitordata.setSampledate(parse);
                                                }

                                                if (itemCode != null && !"".equals(itemCode)) {
                                                    WqDataIntegrationmonitordata.setItemcode(String.valueOf(itemCode));
                                                }
                                                if (itemName != null && !"".equals(itemName)) {
                                                    WqDataIntegrationmonitordata.setItemname(String.valueOf(itemName));
                                                }
                                                if (effectiveValue != null && !"".equals(effectiveValue) && Double.valueOf(String.valueOf(effectiveValue)) > 0) {
                                                    boolean match = StringUtils.isMatch(String.valueOf(effectiveValue));
                                                    String valueDatass = "";
                                                    if (match) {
                                                        valueDatass = String.valueOf(effectiveValue);
                                                        if (effectiveValue != null && !"".equals(effectiveValue)) {
                                                            Double aDouble = Double.valueOf(String.valueOf(effectiveValue));
                                                            double v = aDouble / 2;
                                                            effectiveValue = String.valueOf(v);
                                                        }
                                                        //判断是否科学计算法，如果是就进行转换
                                                        boolean scientificNotation = StringUtils.isScientificNotation(String.valueOf(effectiveValue));
                                                        if (scientificNotation) {
                                                            BigDecimal bigDecimal = new BigDecimal(String.valueOf(effectiveValue));
                                                            String effectiveValuesdatas = bigDecimal.toPlainString();
                                                            effectiveValue = effectiveValuesdatas;
                                                        } else {
                                                            effectiveValue = String.valueOf(effectiveValue);
                                                        }
                                                    }

                                                    WqDataIntegrationmonitordata.setEffectivevalue(new BigDecimal(String.valueOf(effectiveValue)));
                                                } else {
                                                    if (OrginalValue != null && !"".equals(OrginalValue) && !"-1".equals(OrginalValue)) {
                                                        boolean match = StringUtils.isMatch(String.valueOf(OrginalValue));
                                                        String valueDatass = "";
                                                        Double sname = 0.0;
                                                        if (match) {
                                                            valueDatass = String.valueOf(OrginalValue);
                                                            if (!"null".equals(valueDatass) && valueDatass != null && !"".equals(valueDatass)) {
                                                                valueDatass = StringUtils.validateCharacterString(String.valueOf(valueDatass));
                                                                Double aDouble = Double.valueOf(String.valueOf(valueDatass));
                                                                sname = aDouble / 2;
                                                            }
                                                            if (sname > 0) {
                                                                Double aDouble = SegmentFormula.ConvertData(sname);
                                                                WqDataIntegrationmonitordata.setEffectivevalue(new BigDecimal(String.valueOf(aDouble)));
                                                            }

                                                        } else {
                                                            Double aDouble = SegmentFormula.ConvertData(Double.valueOf(String.valueOf(OrginalValue)));
                                                            if (aDouble != null && !"".equals(aDouble)) {
                                                                WqDataIntegrationmonitordata.setEffectivevalue(new BigDecimal(String.valueOf(aDouble)));

                                                            }

                                                        }
                                                    }
                                                }
                                                if(StringUtils.isNotNull(dataSource)){
                                                    WqDataIntegrationmonitordata.setDatasource(String.valueOf(dataSource));
                                                }else{
                                                    WqDataIntegrationmonitordata.setDatasource("");
                                                }

                                                if (remark != null && !"".equals(remark)) {
                                                    WqDataIntegrationmonitordata.setRemark(String.valueOf(remark));
                                                }
                                                if (bussinessCategory != null && !"".equals(bussinessCategory)) {
                                                    WqDataIntegrationmonitordata.setBussinesscategory(String.valueOf(bussinessCategory));
                                                }

                                                if (bussinessCategoryCode != null && !"".equals(bussinessCategoryCode)) {
                                                    WqDataIntegrationmonitordata.setBussinesscategorycode(String.valueOf(bussinessCategoryCode));
                                                }
                                                if (reportID != null && !"".equals(reportID)) {
                                                    WqDataIntegrationmonitordata.setReportid(String.valueOf(reportID));
                                                }
                                                if (segmentName != null && !"".equals(segmentName)) {
                                                    WqDataIntegrationmonitordata.setSegmentname(String.valueOf(segmentName));
                                                }
                                                if (id != null && !"".equals(id)) {
                                                    WqDataIntegrationmonitordata.setSegmentid(String.valueOf(id));
                                                }
                                                if (segmentCode != null && !"".equals(segmentCode)) {
                                                    WqDataIntegrationmonitordata.setSegmentcode(String.valueOf(segmentCode));
                                                }

                                                //下面进行数据计算和处理
                                                if (effectiveValue != null && !"".equals(effectiveValue) && !"-1".equals(effectiveValue)) {
                                                    if (sectionStandardCalculationlist != null && sectionStandardCalculationlist.size() > 0) {
                                                        //数据分组  SegmentCategory  ItemCode Level
                                                        //分组判断，stream流 //断面类型
                                                        List<Map<String, Object>> sunmapsitemCodelist = new ArrayList<>();
                                                        Map<String, List<Map<String, Object>>> sunmapsSegmentCategory =
                                                                sectionStandardCalculationlist.stream().collect(
                                                                        Collectors.groupingBy(item -> item.get("WaterType").toString())
                                                                );
                                                        //SegmentCategorys 断面类型分组
                                                        List<Map<String, Object>> sunmapsSegmentCategorylist = sunmapsSegmentCategory.get(String.valueOf(SegmentCategorys));
                                                        //因子名称分组
                                                        if (sunmapsSegmentCategorylist != null && sunmapsSegmentCategorylist.size() > 0) {
                                                            Map<String, List<Map<String, Object>>> sunmapsitemCode =
                                                                    sunmapsSegmentCategorylist.stream().collect(
                                                                            Collectors.groupingBy(item -> item.get("ItemCode").toString())
                                                                    );
                                                            sunmapsitemCodelist = sunmapsitemCode.get(itemCode);
                                                        }
                                                        //断面标准计算进行转换list
                                                        List<Standard> Standardlist = new ArrayList<>();

                                                        if (sunmapsitemCodelist != null && sunmapsitemCodelist.size() > 0) {
                                                            for (Map<String, Object> sunmapsitemCodelistdata : sunmapsitemCodelist) {
                                                                Object standardValue = sunmapsitemCodelistdata.get("StandardValue");//标准值
                                                                Object compareMethod = sunmapsitemCodelistdata.get("CompareMethod");//比对方法（0<= ，1>=，2>，3有或无，4未检出）
                                                                Object Level = sunmapsitemCodelistdata.get("Level");//级别
                                                                WqDataIntegrationmonitordata.setStandardValue(String.valueOf(standardValue));
                                                                if (Level != null && !"".equals(Level)) {
                                                                    if (String.valueOf(Level).equals("1")) {
                                                                        if (compareMethod != null && !"".equals(compareMethod)) {
                                                                            if (compareMethod.equals("0")) {
                                                                                if (Double.valueOf(String.valueOf(effectiveValue)) > Double.valueOf(String.valueOf(standardValue))) {
                                                                                    WqDataIntegrationmonitordata.setIsoverstandard1("1");
                                                                                    Double v = (Double.valueOf(String.valueOf(effectiveValue)) - Double.valueOf(String.valueOf(standardValue))) / Double.valueOf(String.valueOf(standardValue));
                                                                                    String format = df.format(v);
                                                                                    WqDataIntegrationmonitordata.setOverstandardtimes1(format);
                                                                                }
                                                                            }
                                                                            if (compareMethod.equals("1")) {
                                                                                if (Double.valueOf(String.valueOf(effectiveValue)) < Double.valueOf(String.valueOf(standardValue))) {
                                                                                    WqDataIntegrationmonitordata.setIsoverstandard1("1");
                                                                                }
                                                                            }
                                                                            if (compareMethod.equals("2")) {
                                                                                if (Double.valueOf(String.valueOf(effectiveValue)) <= Double.valueOf(String.valueOf(standardValue))) {
                                                                                    WqDataIntegrationmonitordata.setIsoverstandard1("1");
                                                                                }

                                                                            }
                                                                        }
                                                                    }
                                                                    if (String.valueOf(Level).equals("2")) {
                                                                        if (compareMethod != null && !"".equals(compareMethod)) {
                                                                            if (compareMethod.equals("0")) {
                                                                                if (Double.valueOf(String.valueOf(effectiveValue)) > Double.valueOf(String.valueOf(standardValue))) {
                                                                                    WqDataIntegrationmonitordata.setIsoverstandard2("1");
                                                                                    Double v = (Double.valueOf(String.valueOf(effectiveValue)) - Double.valueOf(String.valueOf(standardValue))) / Double.valueOf(String.valueOf(standardValue));
                                                                                    String format = df.format(v);
                                                                                    WqDataIntegrationmonitordata.setOverstandardtimes2(format);
                                                                                }
                                                                            }
                                                                            if (compareMethod.equals("1")) {
                                                                                if (Double.valueOf(String.valueOf(effectiveValue)) < Double.valueOf(String.valueOf(standardValue))) {
                                                                                    WqDataIntegrationmonitordata.setIsoverstandard2("1");
                                                                                }
                                                                            }
                                                                            if (compareMethod.equals("2")) {
                                                                                if (Double.valueOf(String.valueOf(effectiveValue)) <= Double.valueOf(String.valueOf(standardValue))) {
                                                                                    WqDataIntegrationmonitordata.setIsoverstandard2("1");
                                                                                }

                                                                            }
                                                                        }
                                                                    }
                                                                    if (String.valueOf(Level).equals("3")) {
                                                                        if (compareMethod != null && !"".equals(compareMethod)) {
                                                                            if (compareMethod.equals("0")) {
                                                                                if (Double.valueOf(String.valueOf(effectiveValue)) > Double.valueOf(String.valueOf(standardValue))) {
                                                                                    WqDataIntegrationmonitordata.setIsoverstandard3("1");
                                                                                    Double v = (Double.valueOf(String.valueOf(effectiveValue)) - Double.valueOf(String.valueOf(standardValue))) / Double.valueOf(String.valueOf(standardValue));
                                                                                    String format = df.format(v);
                                                                                    WqDataIntegrationmonitordata.setOverstandardtimes3(format);
                                                                                }
                                                                            }
                                                                            if (compareMethod.equals("1")) {
                                                                                if (Double.valueOf(String.valueOf(effectiveValue)) < Double.valueOf(String.valueOf(standardValue))) {
                                                                                    WqDataIntegrationmonitordata.setIsoverstandard3("1");
                                                                                }
                                                                            }
                                                                            if (compareMethod.equals("2")) {
                                                                                if (Double.valueOf(String.valueOf(effectiveValue)) <= Double.valueOf(String.valueOf(standardValue))) {
                                                                                    WqDataIntegrationmonitordata.setIsoverstandard3("1");
                                                                                }

                                                                            }
                                                                        }
                                                                    }
                                                                    if (String.valueOf(Level).equals("4")) {
                                                                        if (compareMethod != null && !"".equals(compareMethod)) {
                                                                            if (compareMethod.equals("0")) {
                                                                                if (Double.valueOf(String.valueOf(effectiveValue)) > Double.valueOf(String.valueOf(standardValue))) {
                                                                                    WqDataIntegrationmonitordata.setIsoverstandard4("1");
                                                                                    Double v = (Double.valueOf(String.valueOf(effectiveValue)) - Double.valueOf(String.valueOf(standardValue))) / Double.valueOf(String.valueOf(standardValue));
                                                                                    String format = df.format(v);
                                                                                    WqDataIntegrationmonitordata.setOverstandardtimes4(format);
                                                                                }
                                                                            }
                                                                            if (compareMethod.equals("1")) {
                                                                                if (Double.valueOf(String.valueOf(effectiveValue)) < Double.valueOf(String.valueOf(standardValue))) {
                                                                                    WqDataIntegrationmonitordata.setIsoverstandard4("1");
                                                                                }
                                                                            }
                                                                            if (compareMethod.equals("2")) {
                                                                                if (Double.valueOf(String.valueOf(effectiveValue)) <= Double.valueOf(String.valueOf(standardValue))) {
                                                                                    WqDataIntegrationmonitordata.setIsoverstandard4("1");
                                                                                }

                                                                            }
                                                                        }
                                                                    }
                                                                    if (String.valueOf(Level).equals("5")) {
                                                                        if (compareMethod != null && !"".equals(compareMethod)) {
                                                                            if (compareMethod.equals("0")) {
                                                                                if (Double.valueOf(String.valueOf(effectiveValue)) > Double.valueOf(String.valueOf(standardValue))) {
                                                                                    WqDataIntegrationmonitordata.setIsoverstandard5("1");
                                                                                    Double v = (Double.valueOf(String.valueOf(effectiveValue)) - Double.valueOf(String.valueOf(standardValue))) / Double.valueOf(String.valueOf(standardValue));
                                                                                    String format = df.format(v);
                                                                                    WqDataIntegrationmonitordata.setOverstandardtimes5(format);
                                                                                }
                                                                            }
                                                                            if (compareMethod.equals("1")) {
                                                                                if (Double.valueOf(String.valueOf(effectiveValue)) < Double.valueOf(String.valueOf(standardValue))) {
                                                                                    WqDataIntegrationmonitordata.setIsoverstandard5("1");
                                                                                }
                                                                            }
                                                                            if (compareMethod.equals("2")) {
                                                                                if (Double.valueOf(String.valueOf(effectiveValue)) <= Double.valueOf(String.valueOf(standardValue))) {
                                                                                    WqDataIntegrationmonitordata.setIsoverstandard5("1");
                                                                                }

                                                                            }
                                                                        }
                                                                    }
                                                                }


                                                            }
                                                        }
                                                        if (sunmapsitemCodelist != null && sunmapsitemCodelist.size() > 0) {
                                                            for (Map s : sunmapsitemCodelist) {
                                                                Standard Standard = new Standard();//计算标准实体类
                                                                Object waterType = s.get("WaterType");//水体类型
                                                                Object StartDate = s.get("StartDate");//开始时间
                                                                Object EndDate = s.get("EndDate");//结束时间
                                                                Object ItemCodes = s.get("ItemCode");//监测项编码
                                                                Object Level = s.get("Level");//水质级别
                                                                Object CompareMethod = s.get("CompareMethod");//比对方法（0<= ，1>=，2>，3有或无，4未检出）
                                                                Object StandardValue = s.get("StandardValue");//标准值
                                                                Object Type = s.get("Type");//监测项目标准分类（常规、特殊）
                                                                Object StandardCategory = s.get("StandardCategory");//标准类别（河流/湖库/地下水）
                                                                //下面判读数据不为空进行数据处理到实体类里面
                                                                if (waterType != null && !"".equals(waterType)) {
                                                                    Standard.setWaterType(String.valueOf(waterType));
                                                                } else {
                                                                    Standard.setWaterType("");
                                                                }
                                                                if (StartDate != null && !"".equals(StartDate)) {
                                                                    String StartDateString = String.valueOf(StartDate);
                                                                    Date StartDateStringparse = null;
                                                                    try {
                                                                        StartDateStringparse = dateFormat.parse(StartDateString);
                                                                    } catch (ParseException e) {
                                                                        e.printStackTrace();
                                                                    }
                                                                    Standard.setStartDate(StartDateStringparse);
                                                                }
                                                                if (EndDate != null && !"".equals(EndDate)) {
                                                                    String EndDateString = String.valueOf(EndDate);
                                                                    Date EndDateStringparse = null;
                                                                    try {
                                                                        EndDateStringparse = dateFormat.parse(EndDateString);
                                                                    } catch (ParseException e) {
                                                                        e.printStackTrace();
                                                                    }
                                                                    Standard.setEndDate(EndDateStringparse);
                                                                }
                                                                if (ItemCodes != null && !"".equals(ItemCodes)) {
                                                                    Standard.setItemCode(String.valueOf(ItemCodes));
                                                                } else {
                                                                    Standard.setItemCode("");
                                                                }
                                                                if (Level != null && !"".equals(Level)) {
                                                                    Standard.setLevel(String.valueOf(Level));
                                                                } else {
                                                                    Standard.setLevel("");
                                                                }
                                                                if (StandardValue != null && !"".equals(StandardValue)) {
                                                                    Standard.setStandardValue(String.valueOf(StandardValue));
                                                                } else {
                                                                    Standard.setStandardValue("");
                                                                }
                                                                if (Type != null && !"".equals(Type)) {
                                                                    Standard.setType(String.valueOf(Type));
                                                                } else {
                                                                    Standard.setType("");
                                                                }
                                                                if (StandardCategory != null && !"".equals(StandardCategory)) {
                                                                    Standard.setStandardCategory(String.valueOf(StandardCategory));
                                                                } else {
                                                                    Standard.setStandardCategory("");
                                                                }
                                                                if (CompareMethod != null && !"".equals(CompareMethod)) {
                                                                    Standard.setCompareMethod(String.valueOf(CompareMethod));
                                                                } else {
                                                                    Standard.setCompareMethod("");
                                                                }
                                                                Standardlist.add(Standard);
                                                            }
                                                        }
                                                        if (itemCode != null && "15DE941F-A221-4D9C-8387-48B0E99F6E25".equals(itemCode)) {
                                                            WqDataIntegrationmonitordata.setStandardValue(String.valueOf("6~9"));
                                                            if (Double.valueOf(String.valueOf(effectiveValue)) >= Double.valueOf(String.valueOf(6)) && Double.valueOf(String.valueOf(effectiveValue)) <= Double.valueOf(String.valueOf(9))) {
                                                                WqDataIntegrationmonitordata.setIsoverstandard1("0");
                                                                WqDataIntegrationmonitordata.setIsoverstandard2("0");
                                                                WqDataIntegrationmonitordata.setIsoverstandard3("0");
                                                                WqDataIntegrationmonitordata.setIsoverstandard4("0");
                                                                WqDataIntegrationmonitordata.setIsoverstandard5("0");
                                                            } else {
                                                                WqDataIntegrationmonitordata.setIsoverstandard1("1");
                                                                WqDataIntegrationmonitordata.setIsoverstandard2("1");
                                                                WqDataIntegrationmonitordata.setIsoverstandard3("1");
                                                                WqDataIntegrationmonitordata.setIsoverstandard4("1");
                                                                WqDataIntegrationmonitordata.setIsoverstandard5("1");
                                                            }
                                                        }

                                                        //计算水质级别
                                                        if (effectiveValue != null && !"".equals(effectiveValue) && !"-1".equals(effectiveValue)) {
                                                            Integer integer = ItemCodeOverData.GetSingleType(Double.valueOf(String.valueOf(effectiveValue)), Standardlist, String.valueOf(itemCode), String.valueOf(effectiveValue), Integer.valueOf(String.valueOf(segmentCategory)));
                                                            //获取到对应级别之后进行转换成水质级别类型名称，返回级别如果不为空 级别*10（因为转换数据需要这种）
                                                            if (integer != null) {
                                                                integer = integer;//断面计算出的级别
                                                            } else {
                                                                //断面计算出的级别
                                                                integer = 0;
                                                            }
                                                            //转换水质级别名称
                                                            String LevelName = WaterLevelCompute.GetLevelName(integer, "");
                                                            WqDataIntegrationmonitordata.setQualityLevelName(LevelName);
                                                            WqDataIntegrationmonitordata.setQualitylevel(String.valueOf(integer));
                                                        }

                                                    }
                                                }
                                                if (targetLevel != null && !"".equals(targetLevel)) {
                                                    Integer integer1 = Integer.valueOf(String.valueOf(targetLevel));
                                                    if (integer1 == 1) {
                                                        if (WqDataIntegrationmonitordata.getIsoverstandard1() != null && !"".equals(WqDataIntegrationmonitordata.getIsoverstandard1())) {
                                                            WqDataIntegrationmonitordata.setIsOverStandard(String.valueOf(WqDataIntegrationmonitordata.getIsoverstandard1()));
                                                        }
                                                        if (WqDataIntegrationmonitordata.getOverstandardtimes1() != null && !"".equals(WqDataIntegrationmonitordata.getOverstandardtimes1())) {
                                                            WqDataIntegrationmonitordata.setOverStandardTimes(String.valueOf(WqDataIntegrationmonitordata.getOverstandardtimes1()));
                                                        }
                                                    }
                                                    if (integer1 == 2) {
                                                        if (WqDataIntegrationmonitordata.getIsoverstandard2() != null && !"".equals(WqDataIntegrationmonitordata.getIsoverstandard2())) {
                                                            WqDataIntegrationmonitordata.setIsOverStandard(String.valueOf(WqDataIntegrationmonitordata.getIsoverstandard2()));
                                                        }
                                                        if (WqDataIntegrationmonitordata.getOverstandardtimes2() != null && !"".equals(WqDataIntegrationmonitordata.getOverstandardtimes2())) {
                                                            WqDataIntegrationmonitordata.setOverStandardTimes(String.valueOf(WqDataIntegrationmonitordata.getOverstandardtimes2()));
                                                        }
                                                    }
                                                    if (integer1 == 3) {
                                                        if (WqDataIntegrationmonitordata.getIsoverstandard3() != null && !"".equals(WqDataIntegrationmonitordata.getIsoverstandard3())) {
                                                            WqDataIntegrationmonitordata.setIsOverStandard(String.valueOf(WqDataIntegrationmonitordata.getIsoverstandard3()));
                                                        }
                                                        if (WqDataIntegrationmonitordata.getOverstandardtimes3() != null && !"".equals(WqDataIntegrationmonitordata.getOverstandardtimes3())) {
                                                            WqDataIntegrationmonitordata.setOverStandardTimes(String.valueOf(WqDataIntegrationmonitordata.getOverstandardtimes3()));
                                                        }
                                                    }
                                                    if (integer1 == 4) {
                                                        if (WqDataIntegrationmonitordata.getIsoverstandard4() != null && !"".equals(WqDataIntegrationmonitordata.getIsoverstandard4())) {
                                                            WqDataIntegrationmonitordata.setIsOverStandard(String.valueOf(WqDataIntegrationmonitordata.getIsoverstandard4()));
                                                        }
                                                        if (WqDataIntegrationmonitordata.getOverstandardtimes4() != null && !"".equals(WqDataIntegrationmonitordata.getOverstandardtimes4())) {
                                                            WqDataIntegrationmonitordata.setOverStandardTimes(String.valueOf(WqDataIntegrationmonitordata.getOverstandardtimes4()));
                                                        }
                                                    }
                                                    if (integer1 == 5) {
                                                        if (WqDataIntegrationmonitordata.getIsoverstandard5() != null && !"".equals(WqDataIntegrationmonitordata.getIsoverstandard5())) {
                                                            WqDataIntegrationmonitordata.setIsOverStandard(String.valueOf(WqDataIntegrationmonitordata.getIsoverstandard5()));
                                                        }
                                                        if (WqDataIntegrationmonitordata.getOverstandardtimes5() != null && !"".equals(WqDataIntegrationmonitordata.getOverstandardtimes5())) {
                                                            WqDataIntegrationmonitordata.setOverStandardTimes(String.valueOf(WqDataIntegrationmonitordata.getOverstandardtimes5()));
                                                        }
                                                    }
                                                }
                                                //根据数据查询是否存在任何更新数据
                                                //判断手工数据是否存在
                                                if (getintegrationmonitordata != null && getintegrationmonitordata.size() > 0) {
                                                    List<Map<String, Object>> getbasicsmonitordatalist = getintegrationmonitordata.stream()
                                                            .filter(item -> String.valueOf(item.get("SegmentID")).equals(String.valueOf(dateid))
                                                                            && String.valueOf(item.get("BussinessCategoryCode")).equals(String.valueOf(bussinessCategoryCode))
                                                                            && String.valueOf(item.get("ItemCode")).equals(String.valueOf(itemCode))
                                                                            && String.valueOf(item.get("SampleDataTimes")).equals(String.valueOf(SampleDatese))
//                                                                && String.valueOf(item.get("SampleDatmonse")).equals(String.valueOf(SampleDatmonse))
                                                                            && String.valueOf(item.get("dataSource")).equals(WqDataIntegrationmonitordata.getDatasource())
                                                            )
                                                            .collect(Collectors.toList());
                                                    //如果存在数据就更新对应id的数据
                                                    String ids = "";
                                                    String isOverStandardses = WqDataIntegrationmonitordata.getIsOverStandard();
                                                    if (isOverStandardses != null && !"".equals(isOverStandardses)) {

                                                    } else {
                                                        WqDataIntegrationmonitordata.setIsOverStandard("0");
                                                    }
                                                    if (getbasicsmonitordatalist != null && getbasicsmonitordatalist.size() > 0) {
                                                        for (Map<String, Object> getbasicsmonitordatalistdata : getbasicsmonitordatalist) {
                                                            Object idse = getbasicsmonitordatalistdata.get("ID");
                                                            ids = String.valueOf(idse);
                                                        }
                                                    }
                                                    if (ids != null && !"".equals(ids)) {
                                                        WqDataIntegrationmonitordata.setId(ids);
                                                        System.out.println(WqDataIntegrationmonitordata.toString());
                                                        busIntegrationmonitordataMapper.updateWq_data_integrationmonitordata(WqDataIntegrationmonitordata);

                                                    } else {
                                                        busIntegrationmonitordataMapper.insertWq_data_integrationmonitordata(WqDataIntegrationmonitordata);
                                                    }

                                                } else {
                                                    busIntegrationmonitordataMapper.insertWq_data_integrationmonitordata(WqDataIntegrationmonitordata);
                                                }
                                            }
                                        }
                                    }

                                }
                            }

                        }
                    }

                }
            }
            //执行监测数据的评价表
            int getintegrationevaluatedata = this.getintegrationevaluatedata(BussinessCategoryCode, SegmentIDlist, minSampleDataTime, maxSampleDataTime);
            //删除临时表里数据
            if (getintegrationevaluatedata > 0) {
                int i = manualMonitorDataMapper.deleteWqDataTempdataByReportID(String.valueOf(reportID1));
            } else {
                Map<String, Object> maptemp = new HashMap<>();
                maptemp.put("ReportID", reportID1);
                maptemp.put("dataStateCode", "0");
                manualMonitorDataMapper.updateWqDataTempdataStateCode(maptemp);
            }
            if (maxSampleDataTime != null && !"".equals(maxSampleDataTime)) {
                Date ksparse = dateFormat.parse(minSampleDataTime);
                Date jsparse = dateFormat.parse(maxSampleDataTime);
                Calendar calendar = Calendar.getInstance(); // 创建Calendar对象
                calendar.setTime(ksparse); // 将日期设置到Calendar对象中
                calendar.add(Calendar.MONTH, -1); // 减去一个月
                Date time = calendar.getTime();
                String ksformat = dateFormatsmon.format(time);
                String jsformat = dateFormatsmon.format(jsparse);
                List<String> monthBetweenDate = DateUtils.getMonthBetweenDate(dateFormatsmon.format(ksparse), dateFormatsmon.format(jsparse));
                if (monthBetweenDate != null && monthBetweenDate.size() > 0) {
                    Map<String, Object> datatimew = new HashMap<>();
                    datatimew.put("ksformat", ksformat);
                    datatimew.put("jsformat", jsformat);
                    datatimew.put("bussinessCategoryCode", BussinessCategoryCode);
                    datatimew.put("segmentIds", SegmentIDlist);
                    List<Map<String, Object>> integralist = manualMonitorDataMapper.integrationevaluatedataQualityLevel(datatimew);
                    for (String dattime : monthBetweenDate) {
                        Date jyparse = dateFormatsmon.parse(dattime);
                        Calendar calendarcs = Calendar.getInstance(); // 创建Calendar对象
                        calendarcs.setTime(jyparse); // 将日期设置到Calendar对象中
                        calendarcs.add(Calendar.MONTH, -1); // 减去一个月
                        String formatjy = dateFormatsmon.format(calendarcs.getTime());
                        if (SegmentIDlist != null && SegmentIDlist.size() > 0) {
                            for (String dataid : SegmentIDlist) {
                                Map<String, Object> WqDataIntegrationevaluatedatamap = new HashMap<>();
                                BusIntegrationevaluatedata WqDataIntegrationevaluatedata = new BusIntegrationevaluatedata();
                                List<Map<String, Object>> sunmapsLevel = integralist.stream()
                                        .filter(item -> item.get("SegmentID").equals(dataid)
                                                && item.get("SampleDatemon").equals(dattime)
                                        )
                                        .collect(Collectors.toList());
                                List<Map<String, Object>> sunmapsLeveljy = integralist.stream()
                                        .filter(item -> item.get("SegmentID").equals(dataid)
                                                && item.get("SampleDatemon").equals(formatjy)
                                        )
                                        .collect(Collectors.toList());
                                if (sunmapsLevel != null && sunmapsLevel.size() > 0) {
                                    if (sunmapsLeveljy != null && sunmapsLeveljy.size() > 0) {
                                        Map<String, Object> stringObjectMap = sunmapsLevel.get(0);
                                        Map<String, Object> stringObjectMapjy = sunmapsLeveljy.get(0);
                                        Object qualityLevel = stringObjectMap.get("QualityLevel");
                                        Object qualityLeveljy = stringObjectMapjy.get("QualityLevel");
                                        //获取前一天的水质等级，然后跟当天的比较
                                        Integer lastQualitylevel = 0;
                                        if (qualityLeveljy != null && !"".equals(qualityLeveljy)) {
                                            lastQualitylevel = Integer.valueOf(String.valueOf(qualityLeveljy));
                                        }
                                        Integer lastQualityleveldtaa = 0;
                                        if (qualityLevel != null && !"".equals(qualityLevel)) {
                                            lastQualityleveldtaa = Integer.valueOf(String.valueOf(qualityLevel));
                                        }
                                        Object ids = stringObjectMap.get("id");
                                        if (ids != null && !"".equals(ids)) {
                                            Map<String, Object> evaluationTrend = segmentFormula.evaluationTrend(lastQualityleveldtaa, lastQualitylevel);
                                            if (evaluationTrend != null && evaluationTrend.size() > 0) {
                                                Object evaluationTrendCode = evaluationTrend.get("evaluationTrendCode");
                                                Object evaluationTrend1 = evaluationTrend.get("evaluationTrend");
                                                WqDataIntegrationevaluatedata.setEvaluationTrend(String.valueOf(evaluationTrend1));
                                                WqDataIntegrationevaluatedata.setEvaluationTrendCode(String.valueOf(evaluationTrendCode));
                                                WqDataIntegrationevaluatedata.setId(String.valueOf(ids));
                                                WqDataIntegrationevaluatedatamap.put("evaluationTrendCode", evaluationTrendCode);
                                                WqDataIntegrationevaluatedatamap.put("evaluationTrend", evaluationTrend1);
                                                WqDataIntegrationevaluatedatamap.put("id", ids);
                                                manualMonitorDataMapper.updateWq_data_integrationevaluatedataEvaluationTrend(WqDataIntegrationevaluatedatamap);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            busMonthlycumulativedataService.moonAssessTypeSegmen();
        } catch (Exception e) {
            System.out.println("" + e);
            // 捕获异常并保存错误信息
            String s = e.toString();// 可以使用getStackTrace()获取更详细的堆栈信息
            // 或者使用e.getMessage()获取异常的详细消息
            String message = e.getMessage();
        }
        return 0;
    }


    public int importDataCoversydyb(Map map) {
        SysConfig sysConfig = new SysConfig();
        List<SysConfig> sysConfigs = sysConfigMapper.selectConfigList(sysConfig);
        Map<String, Double> phbz = new HashMap<>();
        Double phupper = 9.0;
        Double phlower = 6.0;
        try {
            Object reportID1 = map.get("ReportID");
            //查询需要处理的数据
            List<Map<String, Object>> wqDataTempdatalist = manualMonitorDataMapper.wqDataTempdataSegmentIDStatus(map);
            Map<String, Object> dayas = new HashMap<>();

            //先取对应断面的标题然后进行循环处理数据
            //获取时间
            String maxSampleDataTime = null;
            String minSampleDataTime = null;
            String BussinessCategoryCode = null;
            List<String> SampleDataTimelist = new ArrayList<>();
            List<String> SegmentIDlist = new ArrayList<>();
            List<Map<String, Object>> Segmentlist = new ArrayList<>();
            if (wqDataTempdatalist != null && wqDataTempdatalist.size() > 0) {
                for (Map<String, Object> data : wqDataTempdatalist) {
                    Map<String, Object> listmap = new HashMap<>();
                    Object remark = data.get("SegmentOrder");
                    if (remark != null && !"".equals(remark) && String.valueOf(remark).equals("0")) {
                        for (int i = 1; i <= 120; i++) {
                            Object o = data.get("value" + i);
                            if (o != null && !"".equals(o)) {
                                listmap.put("value" + i, o);
                            }
                            Segmentlist.add(listmap);
                        }

                    } else if (remark != null && !"".equals(remark) && !"0".equals(String.valueOf(remark))) {
                        Object SampleDataTime = data.get("SampleDataTimese");
                        Object SegmentID = data.get("SegmentID");
                        maxSampleDataTime = String.valueOf(data.get("maxSampleDataTime"));
                        minSampleDataTime = String.valueOf(data.get("minSampleDataTime"));
                        BussinessCategoryCode = String.valueOf(data.get("BussinessCategoryCode"));
                        boolean contains = SampleDataTimelist.contains(SampleDataTime);
                        boolean sSegmentID = SegmentIDlist.contains(SegmentID);
                        if (contains) {
                        } else {
                            SampleDataTimelist.add(String.valueOf(SampleDataTime));
                        }
                        if (sSegmentID) {
                        } else {
                            SegmentIDlist.add(String.valueOf(SegmentID));
                        }
                    }
                }
            }
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            SimpleDateFormat dateFormats = new SimpleDateFormat("yyyy-MM-dd");
            DecimalFormat df = new DecimalFormat("#0.00");
            //查询手工监测数据是否存在数据
            Map<String, Object> getbasicsmonitordatamap = new HashMap<>();
            //查询因子名称
            List<Map<String, Object>> wqBasItemIDIsRiverEvalutelist = publicToolsMapper.wqBasItemIDIsRiverEvalute(getbasicsmonitordatamap);
            List<Map<String, Object>> sectionStandardCalculationlist = new ArrayList<>();
            //查询对应标准值
            List<Map> sectionStandardCalculationlists = publicToolsMapper.sectionStandardCalculation(getbasicsmonitordatamap);
            if (sectionStandardCalculationlists != null && sectionStandardCalculationlists.size() > 0) {
                for (Map daya : sectionStandardCalculationlists) {
                    sectionStandardCalculationlist.add(daya);
                }
            }
            //查询对应因子修约位数
            List<Map<String, Object>> wqCodBussinessitemsbussinessCategoryCodelist = publicToolsMapper.wqCodBussinessitemsbussinessCategoryCode(getbasicsmonitordatamap);

            if (wqDataTempdatalist != null && wqDataTempdatalist.size() > 0) {
                for (Map<String, Object> data : wqDataTempdatalist) {
                    Object segmentName = data.get("SegmentName");//断面名称
                    Object segmentID = data.get("SegmentID");//断面id
                    Object segmentCode = data.get("SegmentCode");//断面编码
                    Object sampleTime = data.get("SampleTime");//时间
                    Object SampleDataTime = data.get("SampleDataTime");//时间
                    Object segmentOrder = data.get("SegmentOrder");//数据顺序
                    Object reportID = data.get("ReportID");//上传编码
                    Object bussinessCategoryCode = data.get("BussinessCategoryCode");//数据类型编码
                    Object businessCategory = data.get("businessCategory");//数据类型
                    Object horizontalAzimuth = data.get("HorizontalAzimuth");//水平采样方位
                    Object monitorID = data.get("MonitorID");//采样编号 没有默认1
                    Object verticalAzimuth = data.get("VerticalAzimuth");//垂直采样方位
                    Object status = data.get("Status");////0保存入库/1删除不入库
                    Object remark = data.get("Remark");//备注  去等于备注的数据是对应断面标题
                    Object SegmentCategory = data.get("SegmentCategory");//断面类型
                    Object SegmentCategorys = data.get("SegmentCategorys");//断面类型 s
                    Object targetLevels = data.get("targetLevels");//断面类型 s
                    Object targetLevelNames = data.get("targetLevelNames");//断面类型 s
                    Object longitude = data.get("longitude");//断面类型 s
                    Object latitude = data.get("latitude");//断面类型 s
                    Object dataSource = data.get("dataSource");//数据来源
                    List<String> itemp = new ArrayList<>();
                    if (segmentID != null && !"".equals(segmentID)) {
                        List<Map<String, Object>> notcalculatedsegmentID = new ArrayList<>();

                        if (segmentOrder != null && !"0".equals(String.valueOf(segmentOrder))) {
                            if (Segmentlist != null && Segmentlist.size() > 0) {
                                int size = Segmentlist.size();
                                Map<String, Object> datalise = Segmentlist.get(0);
                                //for(Map<String, Object> datalise:Segmentlist){
                                for (int i = 1; i <= datalise.size(); i++) {
                                    BusWaterBasicsmonitordata WqDataBasicsmonitordata = new BusWaterBasicsmonitordata();
                                    //放入对应值
                                    if (targetLevels != null && !"".equals(targetLevels)) {
                                        WqDataBasicsmonitordata.setTargetLevel(Integer.valueOf(String.valueOf(targetLevels)));
                                    }
                                    if (targetLevelNames != null && !"".equals(targetLevelNames)) {
                                        WqDataBasicsmonitordata.setTargetLevelName(String.valueOf(targetLevelNames));
                                    }
                                    if (SegmentCategorys != null && !"".equals(SegmentCategorys)) {
                                        WqDataBasicsmonitordata.setSegmentCategory(String.valueOf(SegmentCategorys));
                                    }
                                    if (monitorID != null && !"".equals(monitorID)) {
                                        WqDataBasicsmonitordata.setMonitorid(String.valueOf(monitorID));
                                    } else {
                                        WqDataBasicsmonitordata.setMonitorid("1");

                                    }
                                    if (longitude != null && !"".equals(longitude)) {
                                        WqDataBasicsmonitordata.setLongitude(String.valueOf(longitude));
                                    }
                                    if (latitude != null && !"".equals(latitude)) {
                                        WqDataBasicsmonitordata.setLatitude(String.valueOf(latitude));
                                    }
                                    WqDataBasicsmonitordata.setIsdetect("0");
                                    if (SampleDataTime != null && !"".equals(SampleDataTime)) {
                                        Date parse = null;
                                        try {
                                            parse = dateFormat.parse(String.valueOf(SampleDataTime));
                                        } catch (ParseException e) {
                                            e.printStackTrace();
                                        }
                                        WqDataBasicsmonitordata.setSampledate(parse);
                                    }
                                    if (businessCategory != null && !"".equals(businessCategory)) {
                                        WqDataBasicsmonitordata.setBussinesscategory(String.valueOf(businessCategory));
                                    }
                                    if (bussinessCategoryCode != null && !"".equals(bussinessCategoryCode)) {
                                        WqDataBasicsmonitordata.setBussinesscategorycode(String.valueOf(bussinessCategoryCode));
                                    }
                                    if (horizontalAzimuth != null && !"".equals(horizontalAzimuth)) {
                                        WqDataBasicsmonitordata.setHorizontalazimuth(String.valueOf(horizontalAzimuth));
                                    } else {
                                        WqDataBasicsmonitordata.setHorizontalazimuth("");
                                    }
                                    if (verticalAzimuth != null && !"".equals(verticalAzimuth)) {
                                        WqDataBasicsmonitordata.setVerticalazimuth(String.valueOf(verticalAzimuth));
                                    }
                                    if (segmentName != null && !"".equals(segmentName)) {
                                        WqDataBasicsmonitordata.setSegmentname(String.valueOf(segmentName));
                                    }
                                    if (reportID != null && !"".equals(reportID)) {
                                        WqDataBasicsmonitordata.setReportid(String.valueOf(reportID));
                                    }
                                    if (segmentID != null && !"".equals(segmentID)) {
                                        WqDataBasicsmonitordata.setSegmentid(String.valueOf(segmentID));
                                    }
                                    if (segmentCode != null && !"".equals(segmentCode)) {
                                        WqDataBasicsmonitordata.setSegmentcode(String.valueOf(segmentCode));
                                    }

                                    //因子标题
                                    String itemCode = "";
                                    Object ItemName = datalise.get("value" + i);
                                    boolean contains = itemp.contains(ItemName);
                                    if (contains) {
                                        System.out.println();
                                    } else {
                                        itemp.add(String.valueOf(ItemName));
                                        List<Map<String, Object>> sunmapsLevel = wqBasItemIDIsRiverEvalutelist.stream()
                                                .filter(item -> item.get("CNName").equals(ItemName)
                                                )
                                                .collect(Collectors.toList());
                                        if (sunmapsLevel != null && sunmapsLevel.size() > 0) {
                                            Object id = sunmapsLevel.get(0).get("ID");
                                            if (id != null && !"".equals(id)) {
                                                itemCode = String.valueOf(id);
                                            }
                                        }
                                        List<Map<String, Object>> notcalculateditemCode = new ArrayList<>();
                                        //上面获取对应因子编码
                                        if (itemCode != null && !"".equals(itemCode)) {
                                            if (notcalculatedsegmentID != null && notcalculatedsegmentID.size() > 0) {
                                                String finalItemCode2 = itemCode;
                                                notcalculateditemCode = notcalculatedsegmentID.stream()
                                                        .filter(item -> item.get("ItemCode").equals(finalItemCode2)
                                                        )
                                                        .collect(Collectors.toList());
                                            }
                                            if (notcalculateditemCode != null && notcalculateditemCode.size() > 0) {
                                                WqDataBasicsmonitordata.setRemark1("1");
                                            }
                                            WqDataBasicsmonitordata.setItemcode(itemCode);
                                        }
                                        if (ItemName != null && !"".equals(ItemName)) {
                                            WqDataBasicsmonitordata.setItemname(String.valueOf(ItemName));
                                        }
                                        //下面循环取参进行数据处理
                                        //获取对应因子值
                                        Object valueData = data.get("value" + i);
                                        //判断电导率*10
                                        if (valueData != null && !"".equals(valueData) && !"null".equals(valueData)) {
                                            boolean match = StringUtils.isMatch(String.valueOf(valueData));
                                            String valueDatass = null;
                                            if (match) {
                                                valueDatass = String.valueOf(valueData);
                                                if (valueData != null && !"".equals(valueData)) {
                                                    valueData = StringUtils.validateCharacterString(String.valueOf(valueData));
                                                    Double aDouble = Double.valueOf(String.valueOf(valueData));
                                                    valueData = aDouble / 2;
                                                    //判断是否科学计算法，如果是就进行转换
                                                    boolean scientificNotation = StringUtils.isScientificNotation(String.valueOf(valueData));
                                                    if (scientificNotation) {
                                                        BigDecimal bigDecimal = new BigDecimal(String.valueOf(valueData));
                                                        String effectiveValuesdatas = bigDecimal.toPlainString();
                                                        valueData = effectiveValuesdatas;
                                                    } else {
                                                        valueData = String.valueOf(valueData);
                                                    }
                                                }
                                            } else {
                                                valueDatass = String.valueOf(valueData);
                                            }

                                            if (valueDatass != null && !"".equals(valueDatass)) {
                                                WqDataBasicsmonitordata.setOrginalvalue(String.valueOf(valueDatass));
                                            } else {
                                                WqDataBasicsmonitordata.setOrginalvalue("-1");
                                            }
                                        }
                                        //下面进行数据计算和处理
                                        if (valueData != null && !"".equals(valueData) && !"-1".equals(valueData) && !"null".equals(valueData)) {
                                            //监测因子进行修约
                                            String xyvalueData = "";
                                            if (valueData != null && !"".equals(valueData) && !"-1".equals(valueData)) {
                                                String keepPointBitss = "3";
                                                boolean b = StringUtils.validateCharacter(String.valueOf(valueData));
                                                if (b) {
                                                    valueData = StringUtils.validateCharacterString(String.valueOf(valueData));
                                                } else {

                                                }
                                                if (wqCodBussinessitemsbussinessCategoryCodelist != null && wqCodBussinessitemsbussinessCategoryCodelist.size() > 0) {
                                                    String finalItemCode = itemCode;
                                                    List<Map<String, Object>> ItemCodeLevel = wqCodBussinessitemsbussinessCategoryCodelist.stream()
                                                            .filter(item -> item.get("BussinessCategoryCode").equals(bussinessCategoryCode)
                                                                    && item.get("ItemCode").equals(finalItemCode)
                                                            )
                                                            .collect(Collectors.toList());
                                                    if (ItemCodeLevel != null && ItemCodeLevel.size() > 0) {
                                                        Object keepPointBits = ItemCodeLevel.get(0).get("KeepPointBits");
                                                        if (keepPointBits != null && !"".equals(keepPointBits)) {
                                                            keepPointBitss = String.valueOf(keepPointBits);
                                                        }
                                                    }
                                                }
                                                //String ws="%."+keepPointBitss+"f";
                                                BigDecimal number = new BigDecimal(String.valueOf(valueData));
                                                BigDecimal roundedNumber = number.setScale(Integer.parseInt(keepPointBitss), RoundingMode.HALF_UP); // 设置保留位数并进行四舍五入

                                                //xyvalueData = String.format(String.valueOf(roundedNumber));
                                                xyvalueData = String.valueOf(number);
                                                WqDataBasicsmonitordata.setEffectivevalue(number);
                                            } else {
                                                xyvalueData = "-1";
                                            }
                                            if (sectionStandardCalculationlist != null && sectionStandardCalculationlist.size() > 0) {
                                                //数据分组  SegmentCategory  ItemCode Level
                                                //分组判断，stream流 //断面类型
                                                List<Map<String, Object>> sunmapsitemCodelist = new ArrayList<>();
                                                Map<String, List<Map<String, Object>>> sunmapsSegmentCategory =
                                                        sectionStandardCalculationlist.stream().collect(
                                                                Collectors.groupingBy(item -> item.get("WaterType").toString())
                                                        );
                                                //SegmentCategorys 断面类型分组
                                                List<Map<String, Object>> sunmapsSegmentCategorylist = sunmapsSegmentCategory.get(String.valueOf(SegmentCategorys));
                                                //因子名称分组
                                                if (sunmapsSegmentCategorylist != null && sunmapsSegmentCategorylist.size() > 0) {
                                                    Map<String, List<Map<String, Object>>> sunmapsitemCode =
                                                            sunmapsSegmentCategorylist.stream().collect(
                                                                    Collectors.groupingBy(item -> item.get("ItemCode").toString())
                                                            );
                                                    sunmapsitemCodelist = sunmapsitemCode.get(itemCode);
                                                }
                                                //断面标准计算进行转换list
                                                List<Standard> Standardlist = new ArrayList<>();
                                                if (sunmapsitemCodelist != null && sunmapsitemCodelist.size() > 0) {
                                                    for (Map<String, Object> sunmapsitemCodelistdata : sunmapsitemCodelist) {
                                                        Object standardValue = sunmapsitemCodelistdata.get("StandardValue");//标准值
                                                        Object compareMethod = sunmapsitemCodelistdata.get("CompareMethod");//比对方法（0<= ，1>=，2>，3有或无，4未检出）
                                                        Object Level = sunmapsitemCodelistdata.get("Level");//级别
                                                        WqDataBasicsmonitordata.setStandardValue(String.valueOf(standardValue));
                                                        if (Level != null && !"".equals(Level)) {
                                                            if (String.valueOf(Level).equals("1")) {
                                                                if (compareMethod != null && !"".equals(compareMethod)) {
                                                                    if (compareMethod.equals("0")) {
                                                                        if (Double.valueOf(String.valueOf(xyvalueData)) > Double.valueOf(String.valueOf(standardValue))) {
                                                                            WqDataBasicsmonitordata.setIsoverstandard1("1");
                                                                            //map.put("Isoverstandard2", "1");
                                                                            //超标倍数=（超标数据-标准）/标准 OverStandardTimes1
                                                                            Double v = (Double.valueOf(String.valueOf(xyvalueData)) - Double.valueOf(String.valueOf(standardValue))) / Double.valueOf(String.valueOf(standardValue));
                                                                            String format = df.format(v);
                                                                            WqDataBasicsmonitordata.setOverstandardtimes1(format);
                                                                            //map.put("Overstandardtimes2", format);
                                                                        }
                                                                    }
                                                                    if (compareMethod.equals("1")) {
                                                                        if (Double.valueOf(String.valueOf(xyvalueData)) < Double.valueOf(String.valueOf(standardValue))) {
                                                                            //map.put("Isoverstandard2", "1");
                                                                            WqDataBasicsmonitordata.setIsoverstandard1("1");
                                                                        }
                                                                    }
                                                                    if (compareMethod.equals("2")) {
                                                                        if (Double.valueOf(String.valueOf(xyvalueData)) <= Double.valueOf(String.valueOf(standardValue))) {
                                                                            // map.put("Isoverstandard2", "1");
                                                                            WqDataBasicsmonitordata.setIsoverstandard1("1");
                                                                        }

                                                                    }
                                                                }
                                                            }
                                                            if (String.valueOf(Level).equals("2")) {
                                                                if (compareMethod != null && !"".equals(compareMethod)) {
                                                                    if (compareMethod.equals("0")) {
                                                                        if (Double.valueOf(String.valueOf(xyvalueData)) > Double.valueOf(String.valueOf(standardValue))) {
                                                                            WqDataBasicsmonitordata.setIsoverstandard2("1");
                                                                            //map.put("Isoverstandard2", "1");
                                                                            //超标倍数=（超标数据-标准）/标准 OverStandardTimes1
                                                                            Double v = (Double.valueOf(String.valueOf(xyvalueData)) - Double.valueOf(String.valueOf(standardValue))) / Double.valueOf(String.valueOf(standardValue));
                                                                            String format = df.format(v);
                                                                            WqDataBasicsmonitordata.setOverstandardtimes2(format);
                                                                            //map.put("Overstandardtimes2", format);
                                                                        }
                                                                    }
                                                                    if (compareMethod.equals("1")) {
                                                                        if (Double.valueOf(String.valueOf(xyvalueData)) < Double.valueOf(String.valueOf(standardValue))) {
                                                                            //map.put("Isoverstandard2", "1");
                                                                            WqDataBasicsmonitordata.setIsoverstandard2("1");
                                                                        }
                                                                    }
                                                                    if (compareMethod.equals("2")) {
                                                                        if (Double.valueOf(String.valueOf(xyvalueData)) <= Double.valueOf(String.valueOf(standardValue))) {
                                                                            // map.put("Isoverstandard2", "1");
                                                                            WqDataBasicsmonitordata.setIsoverstandard2("1");
                                                                        }

                                                                    }
                                                                }
                                                            }
                                                            if (String.valueOf(Level).equals("3")) {
                                                                if (compareMethod != null && !"".equals(compareMethod)) {
                                                                    if (compareMethod.equals("0")) {
                                                                        if (Double.valueOf(String.valueOf(xyvalueData)) > Double.valueOf(String.valueOf(standardValue))) {
                                                                            WqDataBasicsmonitordata.setIsoverstandard3("1");
                                                                            //map.put("Isoverstandard2", "1");
                                                                            //超标倍数=（超标数据-标准）/标准 OverStandardTimes1
                                                                            Double v = (Double.valueOf(String.valueOf(xyvalueData)) - Double.valueOf(String.valueOf(standardValue))) / Double.valueOf(String.valueOf(standardValue));
                                                                            String format = df.format(v);
                                                                            WqDataBasicsmonitordata.setOverstandardtimes3(format);
                                                                            //map.put("Overstandardtimes2", format);
                                                                        }
                                                                    }
                                                                    if (compareMethod.equals("1")) {
                                                                        if (Double.valueOf(String.valueOf(xyvalueData)) < Double.valueOf(String.valueOf(standardValue))) {
                                                                            //map.put("Isoverstandard2", "1");
                                                                            WqDataBasicsmonitordata.setIsoverstandard3("1");
                                                                        }
                                                                    }
                                                                    if (compareMethod.equals("2")) {
                                                                        if (Double.valueOf(String.valueOf(xyvalueData)) <= Double.valueOf(String.valueOf(standardValue))) {
                                                                            // map.put("Isoverstandard2", "1");
                                                                            WqDataBasicsmonitordata.setIsoverstandard3("1");
                                                                        }

                                                                    }
                                                                }
                                                            }
                                                            if (String.valueOf(Level).equals("4")) {
                                                                if (compareMethod != null && !"".equals(compareMethod)) {
                                                                    if (compareMethod.equals("0")) {
                                                                        if (Double.valueOf(String.valueOf(xyvalueData)) > Double.valueOf(String.valueOf(standardValue))) {
                                                                            WqDataBasicsmonitordata.setIsoverstandard4("1");
                                                                            //map.put("Isoverstandard2", "1");
                                                                            //超标倍数=（超标数据-标准）/标准 OverStandardTimes1
                                                                            Double v = (Double.valueOf(String.valueOf(xyvalueData)) - Double.valueOf(String.valueOf(standardValue))) / Double.valueOf(String.valueOf(standardValue));
                                                                            String format = df.format(v);
                                                                            WqDataBasicsmonitordata.setOverstandardtimes4(format);
                                                                            //map.put("Overstandardtimes2", format);
                                                                        }
                                                                    }
                                                                    if (compareMethod.equals("1")) {
                                                                        if (Double.valueOf(String.valueOf(xyvalueData)) < Double.valueOf(String.valueOf(standardValue))) {
                                                                            //map.put("Isoverstandard2", "1");
                                                                            WqDataBasicsmonitordata.setIsoverstandard4("1");
                                                                        }
                                                                    }
                                                                    if (compareMethod.equals("2")) {
                                                                        if (Double.valueOf(String.valueOf(xyvalueData)) > Double.valueOf(String.valueOf(standardValue))) {
                                                                            // map.put("Isoverstandard2", "1");
                                                                            WqDataBasicsmonitordata.setIsoverstandard4("1");
                                                                        }

                                                                    }
                                                                }
                                                            }
                                                            if (String.valueOf(Level).equals("5")) {
                                                                if (compareMethod != null && !"".equals(compareMethod)) {
                                                                    if (compareMethod.equals("0")) {
                                                                        if (Double.valueOf(String.valueOf(xyvalueData)) > Double.valueOf(String.valueOf(standardValue))) {
                                                                            WqDataBasicsmonitordata.setIsoverstandard5("1");
                                                                            //map.put("Isoverstandard2", "1");
                                                                            //超标倍数=（超标数据-标准）/标准 OverStandardTimes1
                                                                            Double v = (Double.valueOf(String.valueOf(xyvalueData)) - Double.valueOf(String.valueOf(standardValue))) / Double.valueOf(String.valueOf(standardValue));
                                                                            String format = df.format(v);
                                                                            WqDataBasicsmonitordata.setOverstandardtimes5(format);
                                                                            //map.put("Overstandardtimes2", format);
                                                                        }
                                                                    }
                                                                    if (compareMethod.equals("1")) {
                                                                        if (Double.valueOf(String.valueOf(xyvalueData)) < Double.valueOf(String.valueOf(standardValue))) {
                                                                            //map.put("Isoverstandard2", "1");
                                                                            WqDataBasicsmonitordata.setIsoverstandard5("1");
                                                                        }
                                                                    }
                                                                    if (compareMethod.equals("2")) {
                                                                        if (Double.valueOf(String.valueOf(xyvalueData)) > Double.valueOf(String.valueOf(standardValue))) {
                                                                            // map.put("Isoverstandard2", "1");
                                                                            WqDataBasicsmonitordata.setIsoverstandard5("1");
                                                                        }

                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                                if (sunmapsitemCodelist != null && sunmapsitemCodelist.size() > 0) {
                                                    for (Map s : sunmapsitemCodelist) {
                                                        Standard Standard = new Standard();//计算标准实体类
                                                        Object waterType = s.get("WaterType");//水体类型
                                                        Object StartDate = s.get("StartDate");//开始时间
                                                        Object EndDate = s.get("EndDate");//结束时间
                                                        Object ItemCodes = s.get("ItemCode");//监测项编码
                                                        Object Level = s.get("Level");//水质级别
                                                        Object CompareMethod = s.get("CompareMethod");//比对方法（0<= ，1>=，2>，3有或无，4未检出）
                                                        Object StandardValue = s.get("StandardValue");//标准值
                                                        Object Type = s.get("Type");//监测项目标准分类（常规、特殊）
                                                        Object StandardCategory = s.get("StandardCategory");//标准类别（河流/湖库/地下水）
                                                        //下面判读数据不为空进行数据处理到实体类里面
                                                        if (waterType != null && !"".equals(waterType)) {
                                                            Standard.setWaterType(String.valueOf(waterType));
                                                        } else {
                                                            Standard.setWaterType("");
                                                        }
                                                        if (StartDate != null && !"".equals(StartDate)) {
                                                            String StartDateString = String.valueOf(StartDate);
                                                            Date StartDateStringparse = null;
                                                            try {
                                                                StartDateStringparse = dateFormat.parse(StartDateString);
                                                            } catch (ParseException e) {
                                                                e.printStackTrace();
                                                            }
                                                            Standard.setStartDate(StartDateStringparse);
                                                        }
                                                        if (EndDate != null && !"".equals(EndDate)) {
                                                            String EndDateString = String.valueOf(EndDate);
                                                            Date EndDateStringparse = null;
                                                            try {
                                                                EndDateStringparse = dateFormat.parse(EndDateString);
                                                            } catch (ParseException e) {
                                                                e.printStackTrace();
                                                            }
                                                            Standard.setEndDate(EndDateStringparse);
                                                        }
                                                        if (ItemCodes != null && !"".equals(ItemCodes)) {
                                                            Standard.setItemCode(String.valueOf(ItemCodes));
                                                        } else {
                                                            Standard.setItemCode("");
                                                        }
                                                        if (Level != null && !"".equals(Level)) {
                                                            Standard.setLevel(String.valueOf(Level));
                                                        } else {
                                                            Standard.setLevel("");
                                                        }
                                                        if (StandardValue != null && !"".equals(StandardValue)) {
                                                            Standard.setStandardValue(String.valueOf(StandardValue));
                                                        } else {
                                                            Standard.setStandardValue("");
                                                        }
                                                        if (Type != null && !"".equals(Type)) {
                                                            Standard.setType(String.valueOf(Type));
                                                        } else {
                                                            Standard.setType("");
                                                        }
                                                        if (StandardCategory != null && !"".equals(StandardCategory)) {
                                                            Standard.setStandardCategory(String.valueOf(StandardCategory));
                                                        } else {
                                                            Standard.setStandardCategory("");
                                                        }
                                                        if (CompareMethod != null && !"".equals(CompareMethod)) {
                                                            Standard.setCompareMethod(String.valueOf(CompareMethod));
                                                        } else {
                                                            Standard.setCompareMethod("");
                                                        }
                                                        Standardlist.add(Standard);
                                                    }
                                                }
                                                if (itemCode != null && "15DE941F-A221-4D9C-8387-48B0E99F6E25".equals(itemCode)) {
                                                    WqDataBasicsmonitordata.setStandardValue(phlower + "~" + phupper);
                                                    if (Double.valueOf(String.valueOf(xyvalueData)) >= phlower && Double.valueOf(String.valueOf(xyvalueData)) <= phupper) {
                                                        WqDataBasicsmonitordata.setIsoverstandard1("0");
                                                        WqDataBasicsmonitordata.setIsoverstandard2("0");
                                                        WqDataBasicsmonitordata.setIsoverstandard3("0");
                                                        WqDataBasicsmonitordata.setIsoverstandard4("0");
                                                        WqDataBasicsmonitordata.setIsoverstandard5("0");
                                                    } else {
                                                        WqDataBasicsmonitordata.setIsoverstandard1("1");
                                                        WqDataBasicsmonitordata.setIsoverstandard2("1");
                                                        WqDataBasicsmonitordata.setIsoverstandard3("1");
                                                        WqDataBasicsmonitordata.setIsoverstandard4("1");
                                                        WqDataBasicsmonitordata.setIsoverstandard5("1");

                                                    }

                                                }

                                                //计算水质级别
                                                if (xyvalueData != null && !"".equals(xyvalueData) && !"-1".equals(xyvalueData)) {
                                                    Integer integer = ItemCodeOverData.GetSingleType(Double.valueOf(String.valueOf(xyvalueData)), Standardlist, String.valueOf(itemCode), String.valueOf(xyvalueData), Integer.valueOf(String.valueOf(SegmentCategory)));
                                                    //获取到对应级别之后进行转换成水质级别类型名称，返回级别如果不为空 级别*10（因为转换数据需要这种）
                                                    if (integer != null) {
                                                        integer = integer;//断面计算出的级别
                                                    } else {
                                                        //断面计算出的级别
                                                        integer = 0;
                                                    }
                                                    //转换水质级别名称
                                                    String LevelName = WaterLevelCompute.GetLevelName(integer, "");
                                                    WqDataBasicsmonitordata.setQualityLevelName(LevelName);
                                                    WqDataBasicsmonitordata.setQualitylevel(String.valueOf(integer));
                                                }
                                                if (targetLevels != null && !"".equals(targetLevels)) {
                                                    Integer integer1 = Integer.valueOf(String.valueOf(targetLevels));
                                                    if (integer1 == 1) {
                                                        if (WqDataBasicsmonitordata.getIsoverstandard1() != null && !"".equals(WqDataBasicsmonitordata.getIsoverstandard1())) {
                                                            WqDataBasicsmonitordata.setIsOverStandard(String.valueOf(WqDataBasicsmonitordata.getIsoverstandard1()));
                                                        }
                                                        if (WqDataBasicsmonitordata.getOverstandardtimes1() != null && !"".equals(WqDataBasicsmonitordata.getOverstandardtimes1())) {
                                                            WqDataBasicsmonitordata.setOverStandardTimes(String.valueOf(WqDataBasicsmonitordata.getOverstandardtimes1()));
                                                        }
                                                    }
                                                    if (integer1 == 2) {
                                                        if (WqDataBasicsmonitordata.getIsoverstandard2() != null && !"".equals(WqDataBasicsmonitordata.getIsoverstandard2())) {
                                                            WqDataBasicsmonitordata.setIsOverStandard(String.valueOf(WqDataBasicsmonitordata.getIsoverstandard2()));
                                                        }
                                                        if (WqDataBasicsmonitordata.getOverstandardtimes2() != null && !"".equals(WqDataBasicsmonitordata.getOverstandardtimes2())) {
                                                            WqDataBasicsmonitordata.setOverStandardTimes(String.valueOf(WqDataBasicsmonitordata.getOverstandardtimes2()));
                                                        }
                                                    }
                                                    if (integer1 == 3) {
                                                        if (WqDataBasicsmonitordata.getIsoverstandard3() != null && !"".equals(WqDataBasicsmonitordata.getIsoverstandard3())) {
                                                            WqDataBasicsmonitordata.setIsOverStandard(String.valueOf(WqDataBasicsmonitordata.getIsoverstandard3()));
                                                        }
                                                        if (WqDataBasicsmonitordata.getOverstandardtimes3() != null && !"".equals(WqDataBasicsmonitordata.getOverstandardtimes3())) {
                                                            WqDataBasicsmonitordata.setOverStandardTimes(String.valueOf(WqDataBasicsmonitordata.getOverstandardtimes3()));
                                                        }
                                                    }
                                                    if (integer1 == 4) {
                                                        if (WqDataBasicsmonitordata.getIsoverstandard4() != null && !"".equals(WqDataBasicsmonitordata.getIsoverstandard4())) {
                                                            WqDataBasicsmonitordata.setIsOverStandard(String.valueOf(WqDataBasicsmonitordata.getIsoverstandard4()));
                                                        }
                                                        if (WqDataBasicsmonitordata.getOverstandardtimes4() != null && !"".equals(WqDataBasicsmonitordata.getOverstandardtimes4())) {
                                                            WqDataBasicsmonitordata.setOverStandardTimes(String.valueOf(WqDataBasicsmonitordata.getOverstandardtimes4()));
                                                        }
                                                    }
                                                    if (integer1 == 5) {
                                                        if (WqDataBasicsmonitordata.getIsoverstandard5() != null && !"".equals(WqDataBasicsmonitordata.getIsoverstandard5())) {
                                                            WqDataBasicsmonitordata.setIsOverStandard(String.valueOf(WqDataBasicsmonitordata.getIsoverstandard5()));
                                                        }
                                                        if (WqDataBasicsmonitordata.getOverstandardtimes5() != null && !"".equals(WqDataBasicsmonitordata.getOverstandardtimes5())) {
                                                            WqDataBasicsmonitordata.setOverStandardTimes(String.valueOf(WqDataBasicsmonitordata.getOverstandardtimes5()));
                                                        }
                                                    }
                                                }

                                            }
                                        }
                                        WqDataBasicsmonitordata.setDatasource(String.valueOf(dataSource));

                                        //System.out.println(WqDataBasicsmonitordata.toString()+"*******");
                                        // System.out.println(data.toString()+"*******");
                                        //判断手工数据是否存在
                                        Map<String, Object> getbasicsmonitordatamapse = new HashMap<>();
                                        getbasicsmonitordatamapse.put("SegmentID", segmentID);
                                        getbasicsmonitordatamapse.put("BussinessCategoryCode", bussinessCategoryCode);
                                        getbasicsmonitordatamapse.put("ItemCode", itemCode);
                                        getbasicsmonitordatamapse.put("SampleDate", SampleDataTime);
                                        List<Map<String, Object>> getbasicsmonitordata = busBasicsmonitordataMapper.getbasicsmonitordata(getbasicsmonitordatamapse);
                                        if (getbasicsmonitordata != null && getbasicsmonitordata.size() > 0) {
                                            String finalItemCode1 = itemCode;
                                            List<Map<String, Object>> getbasicsmonitordatalist = getbasicsmonitordata.stream()
                                                    .filter(item -> String.valueOf(item.get("SegmentID")).equals(String.valueOf(segmentID))
                                                            && String.valueOf(item.get("BussinessCategoryCode")).equals(String.valueOf(bussinessCategoryCode))
                                                            && String.valueOf(item.get("ItemCode")).equals(String.valueOf(finalItemCode1))
                                                            && item.get("SampleDataTimes").equals(SampleDataTime)
                                                            && String.valueOf(item.get("datasource")).equals(String.valueOf(dataSource))
                                                    )
                                                    .collect(Collectors.toList());
                                            int getbasicsmonitordatalistsize = getbasicsmonitordatalist.size();
                                            //如果存在数据就更新对应id的数据
                                            String ids = "";
                                            String isOverStandardses = WqDataBasicsmonitordata.getIsOverStandard();
                                            if (isOverStandardses != null && !"".equals(isOverStandardses)) {

                                            } else {
                                                WqDataBasicsmonitordata.setIsOverStandard("0");
                                            }
                                            if (getbasicsmonitordatalist != null && getbasicsmonitordatalist.size() > 0) {
                                                for (Map<String, Object> getbasicsmonitordatalistdata : getbasicsmonitordatalist) {
                                                    Object id = getbasicsmonitordatalistdata.get("ID");
                                                    ids = String.valueOf(id);
                                                }
                                            }
                                            if (ids != null && !"".equals(ids)) {
                                                WqDataBasicsmonitordata.setId(ids);
                                                int i1 = busBasicsmonitordataMapper.updateWq_data_basicsmonitordata(WqDataBasicsmonitordata);
                                            } else {
                                                int i1 = busBasicsmonitordataMapper.insertWq_data_basicsmonitordata(WqDataBasicsmonitordata);
                                            }
                                        } else {
                                            int i1 = busBasicsmonitordataMapper.insertWq_data_basicsmonitordata(WqDataBasicsmonitordata);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            this.getbasicevaluatedata(BussinessCategoryCode, SegmentIDlist, minSampleDataTime, maxSampleDataTime);


            Map<String, Object> getintegrationmonitordatadatamap = new HashMap<>();
            Map<String, Object> getintegrationmonitordatamap = new HashMap<>();
            getintegrationmonitordatadatamap.put("SegmentIDs", SegmentIDlist);
            getintegrationmonitordatadatamap.put("jsSampleTime", maxSampleDataTime);
            getintegrationmonitordatadatamap.put("ksSampleTime", minSampleDataTime);
            getintegrationmonitordatadatamap.put("bussinessCategoryCode", BussinessCategoryCode);
            List<Map<String, Object>> getintegrationmonitordatadata = busIntegrationmonitordataMapper.getintegrationmonitordatadatasyd(getintegrationmonitordatadatamap);
            List<Map<String, Object>> getintegrationmonitordata = busIntegrationmonitordataMapper.getintegrationmonitordata(getintegrationmonitordatadatamap);

            if (SampleDataTimelist != null && SampleDataTimelist.size() > 0) {
                for (String dateTime : SampleDataTimelist) {
                    if (SegmentIDlist != null && SegmentIDlist.size() > 0) {
                        for (String dateid : SegmentIDlist) {
                            if (Segmentlist != null && Segmentlist.size() > 0) {
                                if (getintegrationmonitordatadata != null && getintegrationmonitordatadata.size() > 0) {
                                    List<Map<String, Object>> sunmapsLevel = getintegrationmonitordatadata.stream()
                                            .filter(item -> item.get("ID").equals(dateid)
                                                    && item.get("SampleDate").equals(dateTime))
                                            .collect(Collectors.toList());
                                    //按照数据来源分组
                                    List<String> datasourcesList = new ArrayList<>();
                                    for (Map<String, Object> data : sunmapsLevel) {
                                        String dataSources=String.valueOf( data.get("dataSource"));
                                        if(!datasourcesList.contains(dataSources)){
                                            datasourcesList.add(dataSources);
                                        }
                                    }
                                    for (String datasources : datasourcesList) {
                                        List<Map<String, Object>> sunmapsLevelone = getintegrationmonitordatadata.stream()
                                                .filter(item -> String.valueOf(item.get("dataSource")).equals(datasources))
                                                .collect(Collectors.toList());
                                        if (sunmapsLevelone != null && sunmapsLevelone.size() > 0) {
                                            for (Map<String, Object> data : sunmapsLevelone) {
                                                BusIntegrationmonitordata WqDataIntegrationmonitordata = new BusIntegrationmonitordata();
                                                Object id = data.get("ID");//断面id
                                                Object Remark1 = data.get("Remark1");//
                                                if (Remark1 != null && !"".equals(Remark1)) {
                                                    WqDataIntegrationmonitordata.setRemark1(String.valueOf(Remark1));
                                                }
                                                //断面类型 0地表水 1地下水
                                                Object segmentCategory = data.get("segmentCategory");
                                                //断面类型  0河流/1湖库/2地下水
                                                Object SegmentCategorys = data.get("segmentCategorys");
                                                Object segmentName = data.get("SegmentName");//断面名称
                                                Object segmentCode = data.get("SegmentCode");//断面编码
                                                Object reportID = data.get("ReportID");//上报批次ID
                                                Object horizontalAzimuth = data.get("HorizontalAzimuth");//
                                                Object verticalAzimuth = data.get("VerticalAzimuth");
                                                Object tideType = data.get("TideType");
                                                //断面数据类型编码
                                                Object bussinessCategoryCode = data.get("BussinessCategoryCode");
                                                //断面数据类型
                                                Object bussinessCategory = data.get("BussinessCategory");
                                                Object monitorID = data.get("MonitorID");//默认1
                                                Object isDelete = data.get("IsDelete");//
                                                Object remark = data.get("Remark");//备注
                                                // Object effectiveValue = data.get("EffectiveValue");//均值
                                                Object itemName = data.get("ItemName");//因子名称
                                                Object itemCode = data.get("ItemCode");//因子编码
                                                Object sampleDates = data.get("SampleDates");//时间未格式化
                                                Object SampleDatese = data.get("SampleDatese");//时间未格式化
                                                Object sampleDate = data.get("SampleDate");//格式化后时间
                                                Object targetLevel = data.get("TargetLevel");//目标级别
                                                Object targetLevelName = data.get("TargetLevelName");//目标级别
                                                Object OrginalValue = data.get("OrginalValue");//原始值
                                                Object segmentCategorys = data.get("segmentCategorys");//断面类型 s
                                                Object avgEffectiveValue = data.get("avgEffectiveValue");//均值不修约
                                                String effectiveValue = null;
                                                //监测因子进行修约
                                                if (avgEffectiveValue != null && !"".equals(avgEffectiveValue)) {
                                                    String xyvalueData = "";
                                                    String ysxyvalueData = "";
                                                    if (avgEffectiveValue != null && !"".equals(avgEffectiveValue) && !"-1".equals(avgEffectiveValue)) {
                                                        String keepPointBitss = "3";
                                                        Integer keepPointBitssys = 3;
                                                        boolean b = StringUtils.validateCharacter(String.valueOf(avgEffectiveValue));
                                                        if (b) {
                                                            avgEffectiveValue = StringUtils.validateCharacterString(String.valueOf(avgEffectiveValue));
                                                        } else {

                                                        }
                                                        if (wqCodBussinessitemsbussinessCategoryCodelist != null && wqCodBussinessitemsbussinessCategoryCodelist.size() > 0) {
                                                            List<Map<String, Object>> ItemCodeLevel = wqCodBussinessitemsbussinessCategoryCodelist.stream()
                                                                    .filter(item -> item.get("BussinessCategoryCode").equals(bussinessCategoryCode)
                                                                            && item.get("ItemCode").equals(itemCode)
                                                                    )
                                                                    .collect(Collectors.toList());
                                                            if (ItemCodeLevel != null && ItemCodeLevel.size() > 0) {
                                                                Object keepPointBits = ItemCodeLevel.get(0).get("KeepPointBits");
                                                                if (keepPointBits != null && !"".equals(keepPointBits)) {
                                                                    keepPointBitss = String.valueOf(keepPointBits);
                                                                    keepPointBitssys = Integer.valueOf(String.valueOf(keepPointBits)) + 5;
                                                                }
                                                            }
                                                        }
                                                        String avgdata = BankerSRoundingUtils.sciCal(Double.valueOf(String.valueOf(avgEffectiveValue)), Integer.valueOf(keepPointBitss));

                                                        String ysavgdata = BankerSRoundingUtils.sciCal(Double.valueOf(String.valueOf(avgEffectiveValue)), keepPointBitssys);
                                                        BigDecimal bd = new BigDecimal(String.valueOf(ysavgdata));
                                                        ysavgdata = bd.stripTrailingZeros().toPlainString();
                                                        if (avgdata != null && !"".equals(avgdata)) {
                                                            Double aDouble = Double.valueOf(avgdata);
                                                            if (aDouble <= 0) {
//转换后的监测值进行判读是否有小数位
                                                                boolean contains = avgdata.contains(".");
                                                                if (contains) {
                                                                    Double aDouble1 = SegmentFormula.ConvertData(Double.valueOf(String.valueOf(avgEffectiveValue)));//存在有小数才进行截取有效值
//四舍 保留最后获取小数点后的位数
                                                                    String datav = BankerSRoundingUtils.sciCal(aDouble1, String.valueOf(aDouble1).length());
                                                                    effectiveValue = datav;
                                                                }
                                                            } else {

                                                                effectiveValue = String.valueOf(avgdata);
                                                            }
                                                        }

                                                        ysxyvalueData = String.valueOf(ysavgdata);
                                                    } else {
                                                        xyvalueData = "-1";
                                                        ysxyvalueData = "-1";
                                                    }
                                                    if (ysxyvalueData != null && !"".equals(ysxyvalueData)) {
                                                        WqDataIntegrationmonitordata.setOrginalvalue(ysxyvalueData);
                                                    }
                                                }

                                                if (targetLevel != null && !"".equals(targetLevel)) {
                                                    WqDataIntegrationmonitordata.setTargetLevel(Integer.parseInt(String.valueOf(targetLevel)));
                                                }
                                                if (targetLevelName != null && !"".equals(targetLevelName)) {
                                                    WqDataIntegrationmonitordata.setTargetLevelName(String.valueOf(targetLevelName));
                                                }
                                                if (segmentCategorys != null && !"".equals(segmentCategorys)) {
                                                    WqDataIntegrationmonitordata.setSegmentCategory(String.valueOf(segmentCategorys));
                                                }
                                                //DataSource
                                                if (SampleDatese != null && !"".equals(SampleDatese)) {
                                                    Date parse = null;
                                                    try {
                                                        parse = dateFormat.parse(String.valueOf(SampleDatese));
                                                    } catch (ParseException e) {
                                                        e.printStackTrace();
                                                    }
                                                    WqDataIntegrationmonitordata.setSampledate(parse);
                                                }

                                                if (itemCode != null && !"".equals(itemCode)) {
                                                    WqDataIntegrationmonitordata.setItemcode(String.valueOf(itemCode));
                                                }
                                                if (itemName != null && !"".equals(itemName)) {
                                                    WqDataIntegrationmonitordata.setItemname(String.valueOf(itemName));
                                                }
                                                if (effectiveValue != null && !"".equals(effectiveValue) && Double.valueOf(String.valueOf(effectiveValue)) > 0) {
                                                    //判断是否科学计算法，如果是就进行转换
                                                    boolean scientificNotation = StringUtils.isScientificNotation(String.valueOf(effectiveValue));
                                                    if (scientificNotation) {
                                                        BigDecimal bigDecimal = new BigDecimal(String.valueOf(effectiveValue));
                                                        String effectiveValuesdatas = bigDecimal.toPlainString();
                                                        effectiveValue = effectiveValuesdatas;
                                                    } else {
                                                        effectiveValue = String.valueOf(effectiveValue);
                                                    }
                                                    boolean match = StringUtils.isMatch(String.valueOf(effectiveValue));
                                                    String valueDatass = "";
                                                    if (match) {
                                                        valueDatass = String.valueOf(effectiveValue);
                                                        if (!"nu".equals(effectiveValue) && effectiveValue != null && !"".equals(effectiveValue)) {
                                                            Double aDouble = Double.valueOf(String.valueOf(effectiveValue));
                                                            double v = aDouble / 2;
                                                            effectiveValue = String.valueOf(v);
                                                        }

                                                    }

                                                    WqDataIntegrationmonitordata.setEffectivevalue(new BigDecimal(String.valueOf(effectiveValue)));
                                                } else {
                                                    if (OrginalValue != null && !"".equals(OrginalValue) && !"-1".equals(OrginalValue)) {
                                                        boolean match = StringUtils.isMatch(String.valueOf(OrginalValue));
                                                        String valueDatass = "";
                                                        Double sname = 0.0;
                                                        if (match) {
                                                            valueDatass = String.valueOf(OrginalValue);
                                                            if (valueDatass != null && !"".equals(valueDatass)) {
                                                                valueDatass = StringUtils.validateCharacterString(String.valueOf(valueDatass));
                                                                Double aDouble = Double.valueOf(String.valueOf(valueDatass));
                                                                sname = aDouble / 2;
                                                            }
                                                            if (sname > 0) {
                                                                Double aDouble = SegmentFormula.ConvertData(sname);
                                                                WqDataIntegrationmonitordata.setEffectivevalue(new BigDecimal(String.valueOf(aDouble)));
                                                            }

                                                        } else {
                                                            Double aDouble = SegmentFormula.ConvertData(Double.valueOf(String.valueOf(OrginalValue)));
                                                            if (aDouble != null && aDouble > 0) {
                                                                WqDataIntegrationmonitordata.setEffectivevalue(new BigDecimal(String.valueOf(aDouble)));

                                                            }

                                                        }
                                                    }
                                                }

                                                if(StringUtils.isNotEmpty(datasources) && !"null".equals(datasources)){
                                                    WqDataIntegrationmonitordata.setDatasource(String.valueOf(datasources));
                                                }else{
                                                    WqDataIntegrationmonitordata.setDatasource("");
                                                }

                                                if (remark != null && !"".equals(remark)) {
                                                    WqDataIntegrationmonitordata.setRemark(String.valueOf(remark));
                                                }
                                                if (bussinessCategory != null && !"".equals(bussinessCategory)) {
                                                    WqDataIntegrationmonitordata.setBussinesscategory(String.valueOf(bussinessCategory));
                                                }

                                                if (bussinessCategoryCode != null && !"".equals(bussinessCategoryCode)) {
                                                    WqDataIntegrationmonitordata.setBussinesscategorycode(String.valueOf(bussinessCategoryCode));
                                                }
                                                if (reportID != null && !"".equals(reportID)) {
                                                    WqDataIntegrationmonitordata.setReportid(String.valueOf(reportID));
                                                }
                                                if (segmentName != null && !"".equals(segmentName)) {
                                                    WqDataIntegrationmonitordata.setSegmentname(String.valueOf(segmentName));
                                                }
                                                if (id != null && !"".equals(id)) {
                                                    WqDataIntegrationmonitordata.setSegmentid(String.valueOf(id));
                                                }
                                                if (segmentCode != null && !"".equals(segmentCode)) {
                                                    WqDataIntegrationmonitordata.setSegmentcode(String.valueOf(segmentCode));
                                                }

                                                //下面进行数据计算和处理
                                                if (effectiveValue != null && !"".equals(effectiveValue) && !"-1".equals(effectiveValue)) {
                                                    if (sectionStandardCalculationlist != null && sectionStandardCalculationlist.size() > 0) {
                                                        //数据分组  SegmentCategory  ItemCode Level
                                                        //分组判断，stream流 //断面类型
                                                        List<Map<String, Object>> sunmapsitemCodelist = new ArrayList<>();
                                                        Map<String, List<Map<String, Object>>> sunmapsSegmentCategory =
                                                                sectionStandardCalculationlist.stream().collect(
                                                                        Collectors.groupingBy(item -> item.get("WaterType").toString())
                                                                );
                                                        //SegmentCategorys 断面类型分组
                                                        List<Map<String, Object>> sunmapsSegmentCategorylist = sunmapsSegmentCategory.get(String.valueOf(SegmentCategorys));
                                                        //因子名称分组
                                                        if (sunmapsSegmentCategorylist != null && sunmapsSegmentCategorylist.size() > 0) {
                                                            Map<String, List<Map<String, Object>>> sunmapsitemCode =
                                                                    sunmapsSegmentCategorylist.stream().collect(
                                                                            Collectors.groupingBy(item -> item.get("ItemCode").toString())
                                                                    );
                                                            sunmapsitemCodelist = sunmapsitemCode.get(itemCode);
                                                        }
                                                        //断面标准计算进行转换list
                                                        List<Standard> Standardlist = new ArrayList<>();

                                                        if (sunmapsitemCodelist != null && sunmapsitemCodelist.size() > 0) {
                                                            for (Map<String, Object> sunmapsitemCodelistdata : sunmapsitemCodelist) {
                                                                Object standardValue = sunmapsitemCodelistdata.get("StandardValue");//标准值
                                                                Object compareMethod = sunmapsitemCodelistdata.get("CompareMethod");//比对方法（0<= ，1>=，2>，3有或无，4未检出）
                                                                Object Level = sunmapsitemCodelistdata.get("Level");//级别
                                                                WqDataIntegrationmonitordata.setStandardValue(String.valueOf(standardValue));
                                                                if (Level != null && !"".equals(Level)) {
                                                                    if (String.valueOf(Level).equals("1")) {
                                                                        if (compareMethod != null && !"".equals(compareMethod)) {
                                                                            if (compareMethod.equals("0")) {
                                                                                if (Double.valueOf(String.valueOf(effectiveValue)) > Double.valueOf(String.valueOf(standardValue))) {
                                                                                    WqDataIntegrationmonitordata.setIsoverstandard1("1");
                                                                                    //超标倍数=（超标数据-标准）/标准 OverStandardTimes1
                                                                                    Double v = (Double.valueOf(String.valueOf(effectiveValue)) - Double.valueOf(String.valueOf(standardValue))) / Double.valueOf(String.valueOf(standardValue));
                                                                                    String format = df.format(v);
                                                                                    WqDataIntegrationmonitordata.setOverstandardtimes1(format);
                                                                                }
                                                                            }
                                                                            if (compareMethod.equals("1")) {
                                                                                if (Double.valueOf(String.valueOf(effectiveValue)) < Double.valueOf(String.valueOf(standardValue))) {
                                                                                    WqDataIntegrationmonitordata.setIsoverstandard1("1");
                                                                                }
                                                                            }
                                                                            if (compareMethod.equals("2")) {
                                                                                if (Double.valueOf(String.valueOf(effectiveValue)) <= Double.valueOf(String.valueOf(standardValue))) {
                                                                                    WqDataIntegrationmonitordata.setIsoverstandard1("1");
                                                                                }

                                                                            }
                                                                        }
                                                                    }
                                                                    if (String.valueOf(Level).equals("2")) {
                                                                        if (compareMethod != null && !"".equals(compareMethod)) {
                                                                            if (compareMethod.equals("0")) {
                                                                                if (Double.valueOf(String.valueOf(effectiveValue)) > Double.valueOf(String.valueOf(standardValue))) {
                                                                                    WqDataIntegrationmonitordata.setIsoverstandard2("1");
                                                                                    //超标倍数=（超标数据-标准）/标准 OverStandardTimes1
                                                                                    Double v = (Double.valueOf(String.valueOf(effectiveValue)) - Double.valueOf(String.valueOf(standardValue))) / Double.valueOf(String.valueOf(standardValue));
                                                                                    String format = df.format(v);
                                                                                    WqDataIntegrationmonitordata.setOverstandardtimes2(format);
                                                                                }
                                                                            }
                                                                            if (compareMethod.equals("1")) {
                                                                                if (Double.valueOf(String.valueOf(effectiveValue)) < Double.valueOf(String.valueOf(standardValue))) {
                                                                                    WqDataIntegrationmonitordata.setIsoverstandard2("1");
                                                                                }
                                                                            }
                                                                            if (compareMethod.equals("2")) {
                                                                                if (Double.valueOf(String.valueOf(effectiveValue)) <= Double.valueOf(String.valueOf(standardValue))) {
                                                                                    WqDataIntegrationmonitordata.setIsoverstandard2("1");
                                                                                }

                                                                            }
                                                                        }
                                                                    }
                                                                    if (String.valueOf(Level).equals("3")) {
                                                                        if (compareMethod != null && !"".equals(compareMethod)) {
                                                                            if (compareMethod.equals("0")) {
                                                                                if (Double.valueOf(String.valueOf(effectiveValue)) > Double.valueOf(String.valueOf(standardValue))) {
                                                                                    WqDataIntegrationmonitordata.setIsoverstandard3("1");
                                                                                    //map.put("Isoverstandard2", "1");
                                                                                    //超标倍数=（超标数据-标准）/标准 OverStandardTimes1
                                                                                    Double v = (Double.valueOf(String.valueOf(effectiveValue)) - Double.valueOf(String.valueOf(standardValue))) / Double.valueOf(String.valueOf(standardValue));
                                                                                    String format = df.format(v);
                                                                                    WqDataIntegrationmonitordata.setOverstandardtimes3(format);
                                                                                    //map.put("Overstandardtimes2", format);
                                                                                }
                                                                            }
                                                                            if (compareMethod.equals("1")) {
                                                                                if (Double.valueOf(String.valueOf(effectiveValue)) < Double.valueOf(String.valueOf(standardValue))) {
                                                                                    //map.put("Isoverstandard2", "1");
                                                                                    WqDataIntegrationmonitordata.setIsoverstandard3("1");
                                                                                }
                                                                            }
                                                                            if (compareMethod.equals("2")) {
                                                                                if (Double.valueOf(String.valueOf(effectiveValue)) <= Double.valueOf(String.valueOf(standardValue))) {
                                                                                    // map.put("Isoverstandard2", "1");
                                                                                    WqDataIntegrationmonitordata.setIsoverstandard3("1");
                                                                                }

                                                                            }
                                                                        }
                                                                    }
                                                                    if (String.valueOf(Level).equals("4")) {
                                                                        if (compareMethod != null && !"".equals(compareMethod)) {
                                                                            if (compareMethod.equals("0")) {
                                                                                if (Double.valueOf(String.valueOf(effectiveValue)) > Double.valueOf(String.valueOf(standardValue))) {
                                                                                    WqDataIntegrationmonitordata.setIsoverstandard4("1");
                                                                                    //map.put("Isoverstandard2", "1");
                                                                                    //超标倍数=（超标数据-标准）/标准 OverStandardTimes1
                                                                                    Double v = (Double.valueOf(String.valueOf(effectiveValue)) - Double.valueOf(String.valueOf(standardValue))) / Double.valueOf(String.valueOf(standardValue));
                                                                                    String format = df.format(v);
                                                                                    WqDataIntegrationmonitordata.setOverstandardtimes4(format);
                                                                                    //map.put("Overstandardtimes2", format);
                                                                                }
                                                                            }
                                                                            if (compareMethod.equals("1")) {
                                                                                if (Double.valueOf(String.valueOf(effectiveValue)) < Double.valueOf(String.valueOf(standardValue))) {
                                                                                    //map.put("Isoverstandard2", "1");
                                                                                    WqDataIntegrationmonitordata.setIsoverstandard4("1");
                                                                                }
                                                                            }
                                                                            if (compareMethod.equals("2")) {
                                                                                if (Double.valueOf(String.valueOf(effectiveValue)) > Double.valueOf(String.valueOf(standardValue))) {
                                                                                    // map.put("Isoverstandard2", "1");
                                                                                    WqDataIntegrationmonitordata.setIsoverstandard4("1");
                                                                                }

                                                                            }
                                                                        }
                                                                    }
                                                                    if (String.valueOf(Level).equals("5")) {
                                                                        if (compareMethod != null && !"".equals(compareMethod)) {
                                                                            if (compareMethod.equals("0")) {
                                                                                if (Double.valueOf(String.valueOf(effectiveValue)) > Double.valueOf(String.valueOf(standardValue))) {
                                                                                    WqDataIntegrationmonitordata.setIsoverstandard5("1");
                                                                                    //map.put("Isoverstandard2", "1");
                                                                                    //超标倍数=（超标数据-标准）/标准 OverStandardTimes1
                                                                                    Double v = (Double.valueOf(String.valueOf(effectiveValue)) - Double.valueOf(String.valueOf(standardValue))) / Double.valueOf(String.valueOf(standardValue));
                                                                                    String format = df.format(v);
                                                                                    WqDataIntegrationmonitordata.setOverstandardtimes5(format);
                                                                                    //map.put("Overstandardtimes2", format);
                                                                                }
                                                                            }
                                                                            if (compareMethod.equals("1")) {
                                                                                if (Double.valueOf(String.valueOf(effectiveValue)) < Double.valueOf(String.valueOf(standardValue))) {
                                                                                    //map.put("Isoverstandard2", "1");
                                                                                    WqDataIntegrationmonitordata.setIsoverstandard5("1");
                                                                                }
                                                                            }
                                                                            if (compareMethod.equals("2")) {
                                                                                if (Double.valueOf(String.valueOf(effectiveValue)) > Double.valueOf(String.valueOf(standardValue))) {
                                                                                    // map.put("Isoverstandard2", "1");
                                                                                    WqDataIntegrationmonitordata.setIsoverstandard5("1");
                                                                                }

                                                                            }
                                                                        }
                                                                    }
                                                                }


                                                            }
                                                        }
                                                        if (sunmapsitemCodelist != null && sunmapsitemCodelist.size() > 0) {
                                                            for (Map s : sunmapsitemCodelist) {
                                                                Standard Standard = new Standard();//计算标准实体类
                                                                Object waterType = s.get("WaterType");//水体类型
                                                                Object StartDate = s.get("StartDate");//开始时间
                                                                Object EndDate = s.get("EndDate");//结束时间
                                                                Object ItemCodes = s.get("ItemCode");//监测项编码
                                                                Object Level = s.get("Level");//水质级别
                                                                Object CompareMethod = s.get("CompareMethod");//比对方法（0<= ，1>=，2>，3有或无，4未检出）
                                                                Object StandardValue = s.get("StandardValue");//标准值
                                                                Object Type = s.get("Type");//监测项目标准分类（常规、特殊）
                                                                Object StandardCategory = s.get("StandardCategory");//标准类别（河流/湖库/地下水）
                                                                //下面判读数据不为空进行数据处理到实体类里面
                                                                if (waterType != null && !"".equals(waterType)) {
                                                                    Standard.setWaterType(String.valueOf(waterType));
                                                                } else {
                                                                    Standard.setWaterType("");
                                                                }
                                                                if (StartDate != null && !"".equals(StartDate)) {
                                                                    String StartDateString = String.valueOf(StartDate);
                                                                    Date StartDateStringparse = null;
                                                                    try {
                                                                        StartDateStringparse = dateFormat.parse(StartDateString);
                                                                    } catch (ParseException e) {
                                                                        e.printStackTrace();
                                                                    }
                                                                    Standard.setStartDate(StartDateStringparse);
                                                                }
                                                                if (EndDate != null && !"".equals(EndDate)) {
                                                                    String EndDateString = String.valueOf(EndDate);
                                                                    Date EndDateStringparse = null;
                                                                    try {
                                                                        EndDateStringparse = dateFormat.parse(EndDateString);
                                                                    } catch (ParseException e) {
                                                                        e.printStackTrace();
                                                                    }
                                                                    Standard.setEndDate(EndDateStringparse);
                                                                }
                                                                if (ItemCodes != null && !"".equals(ItemCodes)) {
                                                                    Standard.setItemCode(String.valueOf(ItemCodes));
                                                                } else {
                                                                    Standard.setItemCode("");
                                                                }
                                                                if (Level != null && !"".equals(Level)) {
                                                                    Standard.setLevel(String.valueOf(Level));
                                                                } else {
                                                                    Standard.setLevel("");
                                                                }
                                                                if (StandardValue != null && !"".equals(StandardValue)) {
                                                                    Standard.setStandardValue(String.valueOf(StandardValue));
                                                                } else {
                                                                    Standard.setStandardValue("");
                                                                }
                                                                if (Type != null && !"".equals(Type)) {
                                                                    Standard.setType(String.valueOf(Type));
                                                                } else {
                                                                    Standard.setType("");
                                                                }
                                                                if (StandardCategory != null && !"".equals(StandardCategory)) {
                                                                    Standard.setStandardCategory(String.valueOf(StandardCategory));
                                                                } else {
                                                                    Standard.setStandardCategory("");
                                                                }
                                                                if (CompareMethod != null && !"".equals(CompareMethod)) {
                                                                    Standard.setCompareMethod(String.valueOf(CompareMethod));
                                                                } else {
                                                                    Standard.setCompareMethod("");
                                                                }
                                                                Standardlist.add(Standard);
                                                            }
                                                        }
                                                        if (itemCode != null && "15DE941F-A221-4D9C-8387-48B0E99F6E25".equals(itemCode)) {
                                                            WqDataIntegrationmonitordata.setStandardValue("6~9");
                                                            if (Double.valueOf(String.valueOf(effectiveValue)) >= phlower && Double.valueOf(String.valueOf(effectiveValue)) <= phupper) {
                                                                WqDataIntegrationmonitordata.setIsoverstandard1("0");
                                                                WqDataIntegrationmonitordata.setIsoverstandard2("0");
                                                                WqDataIntegrationmonitordata.setIsoverstandard3("0");
                                                                WqDataIntegrationmonitordata.setIsoverstandard4("0");
                                                                WqDataIntegrationmonitordata.setIsoverstandard5("0");
                                                            } else {
                                                                WqDataIntegrationmonitordata.setIsoverstandard1("1");
                                                                WqDataIntegrationmonitordata.setIsoverstandard2("1");
                                                                WqDataIntegrationmonitordata.setIsoverstandard3("1");
                                                                WqDataIntegrationmonitordata.setIsoverstandard4("1");
                                                                WqDataIntegrationmonitordata.setIsoverstandard5("1");
                                                            }
                                                        }
                                                        //计算水质级别
                                                        if (effectiveValue != null && !"".equals(effectiveValue) && !"-1".equals(effectiveValue)) {
                                                            Integer integer = ItemCodeOverData.GetSingleType(Double.valueOf(String.valueOf(effectiveValue)), Standardlist, String.valueOf(itemCode), String.valueOf(effectiveValue), Integer.valueOf(String.valueOf(segmentCategory)));
                                                            //获取到对应级别之后进行转换成水质级别类型名称，返回级别如果不为空 级别*10（因为转换数据需要这种）
                                                            if (integer != null) {
                                                                integer = integer;//断面计算出的级别
                                                            } else {
                                                                //断面计算出的级别
                                                                integer = 0;
                                                            }
                                                            //转换水质级别名称
                                                            String LevelName = WaterLevelCompute.GetLevelName(integer, "");
                                                            WqDataIntegrationmonitordata.setQualityLevelName(LevelName);
                                                            WqDataIntegrationmonitordata.setQualitylevel(String.valueOf(integer));
                                                        }

                                                    }
                                                }
                                                if (targetLevel != null && !"".equals(targetLevel)) {
                                                    Integer integer1 = Integer.valueOf(String.valueOf(targetLevel));
                                                    if (integer1 == 1) {
                                                        if (WqDataIntegrationmonitordata.getIsoverstandard1() != null && !"".equals(WqDataIntegrationmonitordata.getIsoverstandard1())) {
                                                            WqDataIntegrationmonitordata.setIsOverStandard(String.valueOf(WqDataIntegrationmonitordata.getIsoverstandard1()));
                                                        }
                                                        if (WqDataIntegrationmonitordata.getOverstandardtimes1() != null && !"".equals(WqDataIntegrationmonitordata.getOverstandardtimes1())) {
                                                            WqDataIntegrationmonitordata.setOverStandardTimes(String.valueOf(WqDataIntegrationmonitordata.getOverstandardtimes1()));
                                                        }
                                                    }
                                                    if (integer1 == 2) {
                                                        if (WqDataIntegrationmonitordata.getIsoverstandard2() != null && !"".equals(WqDataIntegrationmonitordata.getIsoverstandard2())) {
                                                            WqDataIntegrationmonitordata.setIsOverStandard(String.valueOf(WqDataIntegrationmonitordata.getIsoverstandard2()));
                                                        }
                                                        if (WqDataIntegrationmonitordata.getOverstandardtimes2() != null && !"".equals(WqDataIntegrationmonitordata.getOverstandardtimes2())) {
                                                            WqDataIntegrationmonitordata.setOverStandardTimes(String.valueOf(WqDataIntegrationmonitordata.getOverstandardtimes2()));
                                                        }
                                                    }
                                                    if (integer1 == 3) {
                                                        if (WqDataIntegrationmonitordata.getIsoverstandard3() != null && !"".equals(WqDataIntegrationmonitordata.getIsoverstandard3())) {
                                                            WqDataIntegrationmonitordata.setIsOverStandard(String.valueOf(WqDataIntegrationmonitordata.getIsoverstandard3()));
                                                        }
                                                        if (WqDataIntegrationmonitordata.getOverstandardtimes3() != null && !"".equals(WqDataIntegrationmonitordata.getOverstandardtimes3())) {
                                                            WqDataIntegrationmonitordata.setOverStandardTimes(String.valueOf(WqDataIntegrationmonitordata.getOverstandardtimes3()));
                                                        }
                                                    }
                                                    if (integer1 == 4) {
                                                        if (WqDataIntegrationmonitordata.getIsoverstandard4() != null && !"".equals(WqDataIntegrationmonitordata.getIsoverstandard4())) {
                                                            WqDataIntegrationmonitordata.setIsOverStandard(String.valueOf(WqDataIntegrationmonitordata.getIsoverstandard4()));
                                                        }
                                                        if (WqDataIntegrationmonitordata.getOverstandardtimes4() != null && !"".equals(WqDataIntegrationmonitordata.getOverstandardtimes4())) {
                                                            WqDataIntegrationmonitordata.setOverStandardTimes(String.valueOf(WqDataIntegrationmonitordata.getOverstandardtimes4()));
                                                        }
                                                    }
                                                    if (integer1 == 5) {
                                                        if (WqDataIntegrationmonitordata.getIsoverstandard5() != null && !"".equals(WqDataIntegrationmonitordata.getIsoverstandard5())) {
                                                            WqDataIntegrationmonitordata.setIsOverStandard(String.valueOf(WqDataIntegrationmonitordata.getIsoverstandard5()));
                                                        }
                                                        if (WqDataIntegrationmonitordata.getOverstandardtimes5() != null && !"".equals(WqDataIntegrationmonitordata.getOverstandardtimes5())) {
                                                            WqDataIntegrationmonitordata.setOverStandardTimes(String.valueOf(WqDataIntegrationmonitordata.getOverstandardtimes5()));
                                                        }
                                                    }
                                                }
                                                //根据数据查询是否存在任何更新数据
                                                //判断手工数据是否存在
                                                if (getintegrationmonitordata != null && getintegrationmonitordata.size() > 0) {
                                                    List<Map<String, Object>> getbasicsmonitordatalist = getintegrationmonitordata.stream()
                                                            .filter(item -> String.valueOf(item.get("SegmentID")).equals(dateid)
                                                                    && String.valueOf(item.get("BussinessCategoryCode")).equals(String.valueOf(bussinessCategoryCode))
                                                                    && String.valueOf(item.get("ItemCode")).equals(String.valueOf(itemCode))
                                                                    && String.valueOf(item.get("SampleDataTimes")).equals(String.valueOf(SampleDatese))
                                                                    && String.valueOf(item.get("dataSource")).equals(WqDataIntegrationmonitordata.getDatasource())
                                                            )
                                                            .collect(Collectors.toList());
                                                    //如果存在数据就更新对应id的数据
                                                    String ids = "";
                                                    String isOverStandardses = WqDataIntegrationmonitordata.getIsOverStandard();
                                                    if (isOverStandardses != null && !"".equals(isOverStandardses)) {
                                                    } else {
                                                        WqDataIntegrationmonitordata.setIsOverStandard("0");
                                                    }
                                                    if (getbasicsmonitordatalist != null && getbasicsmonitordatalist.size() > 0) {
                                                        for (Map<String, Object> getbasicsmonitordatalistdata : getbasicsmonitordatalist) {
                                                            Object idse = getbasicsmonitordatalistdata.get("ID");
                                                            ids = String.valueOf(idse);
                                                        }
                                                    }
                                                    if (ids != null && !"".equals(ids)) {
                                                        WqDataIntegrationmonitordata.setId(ids);
                                                        System.out.println(WqDataIntegrationmonitordata.toString());
                                                        busIntegrationmonitordataMapper.updateWq_data_integrationmonitordata(WqDataIntegrationmonitordata);

                                                    } else {
                                                        busIntegrationmonitordataMapper.insertWq_data_integrationmonitordata(WqDataIntegrationmonitordata);
                                                    }

                                                } else {
                                                    busIntegrationmonitordataMapper.insertWq_data_integrationmonitordata(WqDataIntegrationmonitordata);
                                                }
                                            }
                                        }
                                    }

                                }
                            }

                        }
                    }

                }
            }
            //执行监测数据的评价表
            int getintegrationevaluatedata = this.getintegrationevaluatedata(BussinessCategoryCode, SegmentIDlist, minSampleDataTime, maxSampleDataTime);
            //删除临时表里数据
            if (getintegrationevaluatedata > 0) {
                int i = manualMonitorDataMapper.deleteWqDataTempdataByReportID(String.valueOf(reportID1));
            }
            busMonthlycumulativedataService.moonAssessTypeSegmens();
        } catch (Exception e) {
            System.out.println("执行手工数据评价表出错:" + e);
            // 捕获异常并保存错误信息
            String s = e.toString();// 可以使用getStackTrace()获取更详细的堆栈信息
            // 或者使用e.getMessage()获取异常的详细消息
            String message = e.getMessage();
            String reportName = null;
            Object reportID1 = map.get("ReportID");
            Map<String, Object> mapda = new HashMap<>();
            mapda.put("ReportID", reportID1);
            List<Map<String, Object>> list = manualMonitorDataMapper.wqDataTempdataReportIDv2(mapda);
            if (list != null && list.size() > 0) {
                Map<String, Object> stringObjectMap = list.get(0);
                if (stringObjectMap != null && stringObjectMap.size() > 0) {
                    Object title = stringObjectMap.get("title");
                    if (title != null && !"".equals(title)) {
                        reportName = String.valueOf(reportName);
                    }

                }
            }
        }
        return 0;
    }


    /**
     * 手工数据评价表执行 （监测数据）
     *
     * @Param SampleDataTimelist 时间
     * SegmentIDlist 断面id
     * minSampleDataTime 开始时间
     * maxSampleDataTime 结束时间
     **/
    public int getbasicevaluatedata(String BussinessCategoryCode, List<String> SegmentIDlist, String minSampleDataTime, String maxSampleDataTime) {
        //水质等级查询出修约需要的数据
        List<Map<String, Object>> hlroundingOffmapsdata = segmentFormula.wqBasStandardcategory(null, null);
        Map<String, Object> wqBasItemIDIsRiverEvalutemap = new HashMap<>();
        wqBasItemIDIsRiverEvalutemap.put("IsRiverEvalute", "1");
        if (BussinessCategoryCode != null && "CBF8".equals(BussinessCategoryCode)) {
            wqBasItemIDIsRiverEvalutemap.put("IsRiverEvalute", "3");
        } else if (BussinessCategoryCode != null && "CBF1".equals(BussinessCategoryCode)) {
            wqBasItemIDIsRiverEvalutemap.put("IsRiverEvalute", "2");
        }
        List<String> ItemCategroylist = new ArrayList<>();
        ItemCategroylist.add("0");
        ItemCategroylist.add("1");
        wqBasItemIDIsRiverEvalutemap.put("ItemCategroylist", ItemCategroylist);
        List<Map<String, Object>> wqBasItemIDIsRiverEvalutelist = publicToolsMapper.wqBasItemIDIsRiverEvalute(wqBasItemIDIsRiverEvalutemap);//

        //查询对应监测断面数据
        SimpleDateFormat sdfsampleTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //设置时间格式
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM"); //设置时间格式
        Map<String, Object> getbasicsmonitordatadatamap = new HashMap<>();
        getbasicsmonitordatadatamap.put("SegmentIDs", SegmentIDlist);
        getbasicsmonitordatadatamap.put("ksSampleTime", minSampleDataTime);
        getbasicsmonitordatadatamap.put("jsSampleTime", maxSampleDataTime);
        getbasicsmonitordatadatamap.put("BussinessCategoryCode", BussinessCategoryCode);
        getbasicsmonitordatadatamap.put("ItemCode", "2");
        getbasicsmonitordatadatamap.put("IsRiverEvalute", "1");
        if (BussinessCategoryCode != null && "CBF8".equals(BussinessCategoryCode)) {
            getbasicsmonitordatadatamap.put("IsRiverEvalute", "3");
        } else if (BussinessCategoryCode != null && "CBF1".equals(BussinessCategoryCode)) {
            getbasicsmonitordatadatamap.put("IsRiverEvalute", "2");
        }
        List<Map<String, Object>> getbasicsmonitordatadata = busBasicsmonitordataMapper.getbasicsmonitordatadatav1(getbasicsmonitordatadatamap);
        //dateTime 根据时间获取前一天小时的时间
        Date ksparse = null;
        Date jsparse = null;
        try {
            ksparse = sdfsampleTime.parse(String.valueOf(minSampleDataTime));
            jsparse = sdfsampleTime.parse(String.valueOf(maxSampleDataTime));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Calendar kscalendar = Calendar.getInstance(); // 获取当前时间的Calendar实例
        kscalendar.setTime(ksparse);
        kscalendar.add(Calendar.MONTH, -1); // 将日期设置为前一天
        Calendar jscalendar = Calendar.getInstance(); // 获取当前时间的Calendar实例
        jscalendar.setTime(jsparse);
        jscalendar.add(Calendar.MONTH, -1); // 将日期设置为前一天
        String ksformat = sdf.format(kscalendar.getTime());
        String jsformat = sdf.format(jscalendar.getTime());
        String jsformats = sdf.format(jsparse);
        getbasicsmonitordatadatamap.put("ksSampleTime", ksformat);
        getbasicsmonitordatadatamap.put("jsSampleTime", jsformat);
        List<Map<String, Object>> tbgetbasicsmonitordatadata = busBasicsmonitordataMapper.getbasicevaluatedatadatahb(getbasicsmonitordatadatamap);
        getbasicsmonitordatadatamap.put("ksSampleTime", ksformat);
        getbasicsmonitordatadatamap.put("jsSampleTime", jsformats);
        List<Map<String, Object>> getbasicevaluatedata = busBasicevaluatedataMapper.getbasicevaluatedata(getbasicsmonitordatadatamap);
        //获取时间
        List<String> SampleDataTimelist = new ArrayList<>();
        List<String> HorizontalAzimuthlist = new ArrayList<>();
        List<String> dataSourceList = new ArrayList<>();
        if (getbasicsmonitordatadata != null && getbasicsmonitordatadata.size() > 0) {
            for (Map<String, Object> dataTIme : getbasicsmonitordatadata) {
                Object sampleDatese = dataTIme.get("SampleDatese");
                Object dataSource = dataTIme.get("dataSource");
                boolean containss = dataSourceList.contains(dataSource);
                if (containss) {
                } else {
                    dataSourceList.add(String.valueOf(dataSource));
                }
                boolean contains = SampleDataTimelist.contains(sampleDatese);
                if (contains) {
                } else {
                    SampleDataTimelist.add(String.valueOf(sampleDatese));
                }
            }
        }


        //根据断面id和时间进行分组处理一个断面一个时间的数据
        if (dataSourceList != null && dataSourceList.size() > 0) {
            for (String dataSource : dataSourceList) {
                if (SampleDataTimelist != null && SampleDataTimelist.size() > 0) {
                    for (String dateTime : SampleDataTimelist) {
                        Date parse1 = null;
                        try {
                            parse1 = sdfsampleTime.parse(dateTime);
                        } catch (ParseException e) {
                            e.printStackTrace();
                        }
                        String formatmon = sdf.format(parse1);
                        //根据断面id进行分组处理一个断面的数据
                        if (SegmentIDlist != null && SegmentIDlist.size() > 0) {
                            for (String SegmentIDdate : SegmentIDlist) {
                                List<String> datastring = new ArrayList<>();//所有因子的水质指数集合
                                if (getbasicsmonitordatadata != null && getbasicsmonitordatadata.size() > 0) {
                                    List<Map<String, Object>> sunmapsLevel = getbasicsmonitordatadata.stream()
                                            .filter(item -> item.get("ID").equals(SegmentIDdate)
                                                    && item.get("SampleDatese").equals(dateTime)
                                                    && item.get("dataSource").equals(dataSource)
                                            )
                                            .collect(Collectors.toList());
                                    //上面根据断面id/时间分组完后的数据进行处理
                                    BusBasicevaluatedata WqDataBasicevaluatedata = new BusBasicevaluatedata();
                                    //临时字段
                                    Integer QualityLevel = 0;
                                    String isOverStandard5s = "0";
                                    String isOverStandard4s = "0";
                                    String isOverStandard3s = "0";
                                    String isOverStandard2s = "0";
                                    String isOverStandard1s = "0";
                                    String overStandardTimes5s = "";
                                    String overStandardTimes4s = "";
                                    String overStandardTimes3s = "";
                                    String overStandardTimes2s = "";
                                    String overStandardTimes1s = "";
                                    String targetLevelse = "";
//                                    String dataSource="";
                                    if (sunmapsLevel != null && sunmapsLevel.size() > 0) {
                                        for (Map<String, Object> data : sunmapsLevel) {
                                            Object id = data.get("ID");//断面id
                                            Object Remark1 = data.get("Remark1");//
                                            if (id != null && !"".equals(id)) {
                                                WqDataBasicevaluatedata.setSegmentid(String.valueOf(id));

                                            }
                                            Object segmentName = data.get("SegmentName");//断面名称
                                            if (segmentName != null && !"".equals(segmentName)) {
                                                WqDataBasicevaluatedata.setSegmentname(String.valueOf(segmentName));

                                            }
                                            Object longitude = data.get("longitude");//断面名称
                                            if (longitude != null && !"".equals(longitude)) {
                                                WqDataBasicevaluatedata.setLongitude(String.valueOf(longitude));

                                            }
                                            Object latitude = data.get("latitude");//断面名称
                                            if (latitude != null && !"".equals(latitude)) {
                                                WqDataBasicevaluatedata.setLatitude(String.valueOf(latitude));

                                            }
//                                            dataSource=String.valueOf(data.get("dataSource"));
                                            //0河流/1湖库/2地下水
                                            Object segmentCategorys = data.get("segmentCategorys");//断面类型
                                            //0地表水 1地下水
                                            Object segmentCategory = data.get("segmentCategory");
                                            //断面编码
                                            Object segmentCode = data.get("SegmentCode");
                                            if (segmentCode != null && !"".equals(segmentCode)) {
                                                WqDataBasicevaluatedata.setSegmentcode(String.valueOf(segmentCode));

                                            }
                                            Object reportID = data.get("ReportID");
                                            if (reportID != null && !"".equals(reportID)) {
                                                WqDataBasicevaluatedata.setReportid(String.valueOf(reportID));

                                            }
                                            Object horizontalAzimuth = data.get("HorizontalAzimuth");
                                            if (horizontalAzimuth != null && !"".equals(horizontalAzimuth)) {
                                                WqDataBasicevaluatedata.setHorizontalazimuth(String.valueOf(horizontalAzimuth));
                                            } else {
                                                WqDataBasicevaluatedata.setHorizontalazimuth(String.valueOf("中_表层"));

                                            }
                                            Object verticalAzimuth = data.get("VerticalAzimuth");
                                            if (verticalAzimuth != null && !"".equals(verticalAzimuth)) {
                                                WqDataBasicevaluatedata.setVerticalazimuth(String.valueOf(verticalAzimuth));
                                            }
                                            Object tideType = data.get("TideType");
                                            if (tideType != null && !"".equals(tideType)) {
                                                WqDataBasicevaluatedata.setTidetype(String.valueOf(tideType));
                                            }
                                            //数据编码
                                            Object bussinessCategoryCode = data.get("BussinessCategoryCode");
                                            if (bussinessCategoryCode != null && !"".equals(bussinessCategoryCode)) {
                                                WqDataBasicevaluatedata.setBussinesscategorycode(String.valueOf(bussinessCategoryCode));
                                            }
                                            //数据名称
                                            Object bussinessCategory = data.get("BussinessCategory");
                                            if (bussinessCategory != null && !"".equals(bussinessCategory)) {
                                                WqDataBasicevaluatedata.setBussinesscategory(String.valueOf(bussinessCategory));
                                            }
                                            Object monitorID = data.get("MonitorID");//默认1
                                            if (monitorID != null && !"".equals(monitorID)) {
                                                WqDataBasicevaluatedata.setMonitorid(String.valueOf(monitorID));
                                            }
                                            Object isDelete = data.get("IsDelete");
                                            if (isDelete != null && !"".equals(isDelete)) {
                                                WqDataBasicevaluatedata.setIsdelete(Integer.valueOf(String.valueOf(isDelete)));
                                            }
                                            Object remark = data.get("Remark");//备注
                                            if (remark != null && !"".equals(remark)) {
                                                WqDataBasicevaluatedata.setRemark(String.valueOf(remark));
                                            }
                                            Object orginalValue = data.get("OrginalValue");
                                            Object itemName = data.get("ItemName");//因子名称
                                            Object itemCode = data.get("ItemCode");//因子编码
                                            if (Remark1 != null && !"".equals(Remark1) && "1".equals(String.valueOf(Remark1))) {

                                            } else {
                                                //0正常 1超标
                                                Object isOverStandard5 = data.get("IsOverStandard5");//五类是否超标
                                                if (isOverStandard5 != null && !"".equals(isOverStandard5)) {
                                                    isOverStandard5s = String.valueOf(isOverStandard5);
                                                }
                                                Object overStandardTimes5 = data.get("OverStandardTimes5");//超标倍数+因子
                                                if (overStandardTimes5 != null && !"".equals(overStandardTimes5)) {
                                                    if (overStandardTimes5s != null && !"".equals(overStandardTimes5s)) {
                                                        overStandardTimes5s = overStandardTimes5s + "," + String.valueOf(overStandardTimes5);
                                                    } else {
                                                        overStandardTimes5s = String.valueOf(overStandardTimes5);
                                                    }
                                                } else if (isOverStandard5 != null && !"".equals(isOverStandard5) && "1".equals(isOverStandard5)) {
                                                    if (overStandardTimes5s != null && !"".equals(overStandardTimes5s)) {
                                                        overStandardTimes5s = overStandardTimes5s + "," + String.valueOf(itemName);
                                                    } else {
                                                        overStandardTimes5s = String.valueOf(itemName);
                                                    }
                                                    // overStandardTimes5s=String.valueOf(itemName);
                                                }
                                                Object isOverStandard4 = data.get("IsOverStandard4");
                                                if (isOverStandard4 != null && !"".equals(isOverStandard4)) {
                                                    isOverStandard4s = String.valueOf(isOverStandard4);
                                                }
                                                Object overStandardTimes4 = data.get("OverStandardTimes4");
                                                if (overStandardTimes4 != null && !"".equals(overStandardTimes4)) {
                                                    if (overStandardTimes4s != null && !"".equals(overStandardTimes4s)) {
                                                        overStandardTimes4s = overStandardTimes4s + "," + String.valueOf(overStandardTimes4);
                                                    } else {
                                                        overStandardTimes4s = String.valueOf(overStandardTimes4);
                                                    }
                                                } else if (isOverStandard4 != null && !"".equals(isOverStandard4) && "1".equals(isOverStandard4)) {
                                                    if (overStandardTimes4s != null && !"".equals(overStandardTimes4s)) {
                                                        overStandardTimes4s = overStandardTimes4s + "," + String.valueOf(itemName);
                                                    } else {
                                                        overStandardTimes4s = String.valueOf(itemName);
                                                    }
                                                    // overStandardTimes4s=String.valueOf(itemName);
                                                }
                                                Object isOverStandard3 = data.get("IsOverStandard3");
                                                if (isOverStandard3 != null && !"".equals(isOverStandard3)) {
                                                    isOverStandard3s = String.valueOf(isOverStandard3);
                                                }
                                                Object overStandardTimes3 = data.get("OverStandardTimes3");
                                                if (overStandardTimes3 != null && !"".equals(overStandardTimes3)) {
                                                    if (overStandardTimes3s != null && !"".equals(overStandardTimes3s)) {
                                                        overStandardTimes3s = overStandardTimes3s + "," + String.valueOf(overStandardTimes3);
                                                    } else {
                                                        overStandardTimes3s = String.valueOf(overStandardTimes3);
                                                    }
                                                } else if (isOverStandard3 != null && !"".equals(isOverStandard3) && "1".equals(isOverStandard3)) {
                                                    if (overStandardTimes3s != null && !"".equals(overStandardTimes3s)) {
                                                        overStandardTimes3s = overStandardTimes3s + "," + String.valueOf(itemName);
                                                    } else {
                                                        overStandardTimes3s = String.valueOf(itemName);
                                                    }
                                                    // overStandardTimes3s=String.valueOf(itemName);
                                                }
                                                Object isOverStandard2 = data.get("IsOverStandard2");
                                                if (isOverStandard2 != null && !"".equals(isOverStandard2)) {
                                                    isOverStandard2s = String.valueOf(isOverStandard2);
                                                }
                                                Object overStandardTimes2 = data.get("OverStandardTimes2");
                                                if (overStandardTimes2 != null && !"".equals(overStandardTimes2)) {
                                                    if (overStandardTimes2s != null && !"".equals(overStandardTimes2s)) {
                                                        overStandardTimes2s = overStandardTimes2s + "," + String.valueOf(overStandardTimes2);
                                                    } else {
                                                        overStandardTimes2s = String.valueOf(overStandardTimes2);
                                                    }
                                                } else if (isOverStandard2 != null && !"".equals(isOverStandard2) && "1".equals(isOverStandard2)) {
                                                    if (overStandardTimes2s != null && !"".equals(overStandardTimes2s)) {
                                                        overStandardTimes2s = overStandardTimes2s + "," + String.valueOf(itemName);
                                                    } else {
                                                        overStandardTimes2s = String.valueOf(itemName);
                                                    }
                                                    // overStandardTimes2s=String.valueOf(itemName);
                                                }
                                                Object isOverStandard1 = data.get("IsOverStandard1");
                                                if (isOverStandard1 != null && !"".equals(isOverStandard1)) {
                                                    isOverStandard1s = String.valueOf(isOverStandard1);
                                                }
                                                Object overStandardTimes1 = data.get("OverStandardTimes1");
                                                if (overStandardTimes1 != null && !"".equals(overStandardTimes1)) {
                                                    if (overStandardTimes1s != null && !"".equals(overStandardTimes1s)) {
                                                        overStandardTimes1s = overStandardTimes1s + "," + String.valueOf(overStandardTimes1);
                                                    } else {
                                                        overStandardTimes1s = String.valueOf(overStandardTimes1);
                                                    }
                                                } else if (isOverStandard1 != null && !"".equals(isOverStandard1) && "1".equals(isOverStandard1)) {
                                                    if (overStandardTimes1s != null && !"".equals(overStandardTimes1s)) {
                                                        overStandardTimes1s = overStandardTimes1s + "," + String.valueOf(itemName);
                                                    } else {
                                                        overStandardTimes1s = String.valueOf(itemName);
                                                    }
                                                    //overStandardTimes1s=String.valueOf(itemName);
                                                }
                                                Object qualityLevel = data.get("QualityLevel");//水质级别
                                                if (qualityLevel != null && !"".equals(qualityLevel)) {
                                                    Integer integer = Integer.valueOf(String.valueOf(qualityLevel));
                                                    if (integer > QualityLevel) {
                                                        QualityLevel = integer;
                                                    }
                                                }
                                            }


                                            Object sampleDates = data.get("SampleDates");//时间 未格式

                                            Object sampleDatese = data.get("SampleDatese");//时间 格式化不变时间
                                            Object sampleDate = data.get("SampleDate");//时间 格式化 时分秒 未0
                                            if (sampleDatese != null && !"".equals(sampleDatese)) {
                                                Date parse = null;
                                                try {
                                                    parse = sdfsampleTime.parse(String.valueOf(sampleDatese));
                                                } catch (ParseException e) {
                                                    e.printStackTrace();
                                                }
                                                WqDataBasicevaluatedata.setSampledate(parse);
                                            }
                                            Object targetLevel = data.get("TargetLevel");
                                            Object targetLevelName = data.get("TargetLevelName");
                                            if (targetLevel != null && !"".equals(targetLevel)) {
                                                String s = String.valueOf(targetLevel);
                                                targetLevelse = s;
                                                WqDataBasicevaluatedata.setTargetLevel(Integer.valueOf(String.valueOf(targetLevel)));
                                            }
                                            if (targetLevelName != null && !"".equals(targetLevelName)) {
                                                WqDataBasicevaluatedata.setTargetLevelName(String.valueOf(targetLevelName));
                                            }
                                            if (segmentCategory != null && !"".equals(segmentCategory)) {
                                                WqDataBasicevaluatedata.setSegmentCategory(String.valueOf(segmentCategory));
                                            }
                                            Object EffectiveValue = data.get("EffectiveValue");//监测均值
                                            Object segmentCategoryS = data.get("segmentCategorys");//监测均值
                                            if (EffectiveValue != null && !"".equals(EffectiveValue) && Double.valueOf(String.valueOf(EffectiveValue)) > 0) {
//判断是否科学计算法，如果是就进行转换
                                                boolean scientificNotation = StringUtils.isScientificNotation(String.valueOf(EffectiveValue));
                                                if (scientificNotation) {
                                                    BigDecimal bigDecimal = new BigDecimal(String.valueOf(EffectiveValue));
                                                    String effectiveValuesdatas = bigDecimal.toPlainString();
                                                    EffectiveValue = effectiveValuesdatas;
                                                } else {
                                                    EffectiveValue = String.valueOf(EffectiveValue);
                                                }
                                                //水质指数计算
                                                if (bussinessCategoryCode != null && !"CBF1".equals(bussinessCategoryCode) && !"CBF8".equals(bussinessCategoryCode)) {
                                                    //调用工具返回对应指数计算后的值 // _IN 指数 _V 均值
                                                    if (wqBasItemIDIsRiverEvalutelist != null && wqBasItemIDIsRiverEvalutelist.size() > 0) {
                                                        List<Map<String, Object>> wqBasItemIDIsRiverEvalute = wqBasItemIDIsRiverEvalutelist.stream()
                                                                .filter(item -> item.get("ID").equals(itemCode)
                                                                )
                                                                .collect(Collectors.toList());
                                                        if (wqBasItemIDIsRiverEvalute != null && wqBasItemIDIsRiverEvalute.size() > 0) {
                                                            if (itemName != null && !"".equals(itemName)) {
                                                                //获取修约的标准值
                                                                String roundingOffstandardValue = "0";
                                                                //获取计算水质指数的标准值
                                                                String indexstandardValue = "0";
                                                                //分组查询
                                                                if (hlroundingOffmapsdata != null && hlroundingOffmapsdata.size() > 0) {
                                                                    //WaterType Level
                                                                    List<Map<String, Object>> roundingOffmaps = hlroundingOffmapsdata.stream()
                                                                            .filter(item -> item.get("WaterType").equals(String.valueOf(segmentCategoryS))
                                                                                    && item.get("Level").equals("1")
                                                                            )
                                                                            .collect(Collectors.toList());
                                                                    List<Map<String, Object>> indexmaps = hlroundingOffmapsdata.stream()
                                                                            .filter(item -> item.get("WaterType").equals(String.valueOf(segmentCategoryS))
                                                                                    && item.get("Level").equals("3")
                                                                            )
                                                                            .collect(Collectors.toList());
                                                                    if (roundingOffmaps != null && roundingOffmaps.size() > 0) {
                                                                        for (Map<String, Object> datas : roundingOffmaps) {
                                                                            Object standardValue = datas.get("StandardValue");//标准值
                                                                            Object itemCodedata = datas.get("ItemCode");//因子编码
                                                                            if (itemCode != null && !"".equals(itemCode) && itemCodedata.equals(itemCode)) {
                                                                                roundingOffstandardValue = String.valueOf(standardValue);
                                                                            }
                                                                        }
                                                                    }


                                                                    if (indexmaps != null && indexmaps.size() > 0) {
                                                                        for (Map<String, Object> datas : indexmaps) {
                                                                            Object standardValue = datas.get("StandardValue");//标准值
                                                                            Object itemCodedata = datas.get("ItemCode");//因子编码
                                                                            if (itemCode != null && !"".equals(itemCode) && itemCodedata.equals(itemCode)) {
                                                                                indexstandardValue = String.valueOf(standardValue);
                                                                            }
                                                                        }
                                                                    }


                                                                }
                                                                //itemName 监测值名称, type 断面类型, beginTime 开始时间, endTime 结束时间, itemdata 监测值
                                                                // indexstandardLimits 计算水质指数的标准值  roundingOffstandardLimits 计算均值修约的数据 itemName 监测值名称, type 断面类型, beginTime 开始时间, endTime 结束时间, itemdata 监测值]
                                                                Map maplistData = segmentFormula.itemDataINV(indexstandardValue, roundingOffstandardValue, String.valueOf(itemCode), String.valueOf(itemName), String.valueOf(segmentCategoryS), "", "", String.valueOf(EffectiveValue));
                                                                if (maplistData != null && maplistData.size() > 0) {
                                                                    Object v = maplistData.get("_V"); //修约后的值
                                                                    Object in = maplistData.get("_IN");//单个因子的指数
                                                                    Object itemCodeData = maplistData.get("itemCode");//因子编码/id
                                                                    maplistData.put(itemCode + "_IN", in);//水质指数
                                                                    if (in != null && !"".equals(in)) {
                                                                        datastring.add(String.valueOf(in));
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        //调用完工具类后所有水质指数进行相加总和数据
                                        if (datastring != null && datastring.size() > 0) {
                                            String dataValue = segmentFormula.riverWaterQualityIndex(datastring);
                                            WqDataBasicevaluatedata.setSegmentIndex(dataValue);
                                        }
                                        if (overStandardTimes1s != null && !"".equals(overStandardTimes1s)) {
                                            WqDataBasicevaluatedata.setIsoverstandard1("1");
                                        } else {
                                            WqDataBasicevaluatedata.setIsoverstandard1(isOverStandard1s);
                                        }
                                        if (overStandardTimes2s != null && !"".equals(overStandardTimes2s)) {
                                            WqDataBasicevaluatedata.setIsoverstandard2("1");
                                        } else {
                                            WqDataBasicevaluatedata.setIsoverstandard2(isOverStandard2s);
                                        }
                                        if (overStandardTimes3s != null && !"".equals(overStandardTimes3s)) {
                                            WqDataBasicevaluatedata.setIsoverstandard3("1");
                                        } else {
                                            WqDataBasicevaluatedata.setIsoverstandard3(isOverStandard3s);
                                        }
                                        if (overStandardTimes4s != null && !"".equals(overStandardTimes4s)) {
                                            WqDataBasicevaluatedata.setIsoverstandard4("1");
                                        } else {
                                            WqDataBasicevaluatedata.setIsoverstandard4(isOverStandard4s);
                                        }
                                        if (overStandardTimes5s != null && !"".equals(overStandardTimes5s)) {
                                            WqDataBasicevaluatedata.setIsoverstandard5("1");
                                        } else {
                                            WqDataBasicevaluatedata.setIsoverstandard5(isOverStandard5s);
                                        }

                                        WqDataBasicevaluatedata.setOverstandarddescribe1(overStandardTimes1s);
                                        WqDataBasicevaluatedata.setOverstandarddescribe2(overStandardTimes2s);
                                        WqDataBasicevaluatedata.setOverstandarddescribe3(overStandardTimes3s);
                                        WqDataBasicevaluatedata.setOverstandarddescribe4(overStandardTimes4s);
                                        WqDataBasicevaluatedata.setOverstandarddescribe5(overStandardTimes5s);
                                        if (QualityLevel != null && !"".equals(QualityLevel)) {
                                            WqDataBasicevaluatedata.setQualitylevel(QualityLevel);
                                            //转换水质级别名称
                                            String LevelName = WaterLevelCompute.GetLevelName(QualityLevel, "无类别");
                                            WqDataBasicevaluatedata.setQualitylevelname(LevelName);
                                            //水质评价结果
                                            Map<String, Object> stringObjectMap = segmentFormula.waterQuality(QualityLevel);
                                            if (stringObjectMap != null && stringObjectMap.size() > 0) {
                                                Object waterQuality = stringObjectMap.get("waterQuality");
                                                WqDataBasicevaluatedata.setWaterQuality(String.valueOf(waterQuality));
                                            }


                                        }
                                        //水质趋势评价
                                        //获取前一天的水质等级，然后跟当天的比较
                                        Integer lastQualitylevel = 0;
                                        //dateTime 根据时间获取前一天小时的时间
                                        Date parse = null;
                                        try {
                                            parse = sdfsampleTime.parse(String.valueOf(dateTime));
                                        } catch (ParseException e) {
                                            e.printStackTrace();
                                        }
                                        Calendar calendar = Calendar.getInstance(); // 获取当前时间的Calendar实例
                                        calendar.setTime(parse);
                                        calendar.add(Calendar.MONTH, -1); // 将日期设置为前一天
                                        String format = sdf.format(calendar.getTime());
                                        if (tbgetbasicsmonitordatadata != null && tbgetbasicsmonitordatadata.size() > 0) {
                                            List<Map<String, Object>> SampleDatesunmapsLevel = tbgetbasicsmonitordatadata.stream()
                                                    .filter(item -> String.valueOf(item.get("SampleDatemon")).equals(format + "-01 00:00:00")
                                                            && String.valueOf(item.get("SegmentID")).equals(String.valueOf(SegmentIDdate))
                                                            && item.get("dataSource").equals(dataSource)
                                                    )
                                                    .collect(Collectors.toList());
                                            if (SampleDatesunmapsLevel != null && SampleDatesunmapsLevel.size() > 0) {
                                                for (Map<String, Object> datasunmapsLevel : SampleDatesunmapsLevel) {
                                                    Object qualityLevel = datasunmapsLevel.get("QualityLevel");
                                                    if (qualityLevel != null && !"".equals(qualityLevel)) {
                                                        Integer integer = Integer.valueOf(String.valueOf(qualityLevel));
                                                        if (integer > lastQualitylevel) {
                                                            lastQualitylevel = integer;
                                                        }

                                                    }
                                                }
                                            }
                                        }

                                        Map<String, Object> evaluationTrend = segmentFormula.evaluationTrend(QualityLevel, lastQualitylevel);
                                        if (evaluationTrend != null && evaluationTrend.size() > 0) {
                                            Object evaluationTrendCode = evaluationTrend.get("evaluationTrendCode");
                                            Object evaluationTrend1 = evaluationTrend.get("evaluationTrend");
                                            WqDataBasicevaluatedata.setEvaluationTrend(String.valueOf(evaluationTrend1));
                                            WqDataBasicevaluatedata.setEvaluationTrendCode(String.valueOf(evaluationTrendCode));
                                        }
                                        WqDataBasicevaluatedata.setDatasource(dataSource);
                                        if (targetLevelse != null && !"".equals(targetLevelse)) {
                                            Integer integer1 = Integer.valueOf(targetLevelse);
                                            if (integer1 == 1) {
                                                if (WqDataBasicevaluatedata.getIsoverstandard1() != null && !"".equals(WqDataBasicevaluatedata.getIsoverstandard1())) {
                                                    WqDataBasicevaluatedata.setIsOverStandard(String.valueOf(WqDataBasicevaluatedata.getIsoverstandard1()));
                                                }
                                                if (overStandardTimes1s != null && !"".equals(overStandardTimes1s)) {
                                                    WqDataBasicevaluatedata.setOverStandardDescribe(String.valueOf(overStandardTimes1s));
                                                }
                                            }
                                            if (integer1 == 2) {
                                                if (WqDataBasicevaluatedata.getIsoverstandard2() != null && !"".equals(WqDataBasicevaluatedata.getIsoverstandard2())) {
                                                    WqDataBasicevaluatedata.setIsOverStandard(String.valueOf(WqDataBasicevaluatedata.getIsoverstandard2()));
                                                }
                                                if (overStandardTimes2s != null && !"".equals(overStandardTimes2s)) {
                                                    WqDataBasicevaluatedata.setOverStandardDescribe(String.valueOf(overStandardTimes2s));
                                                }
                                            }
                                            if (integer1 == 3) {
                                                if (WqDataBasicevaluatedata.getIsoverstandard3() != null && !"".equals(WqDataBasicevaluatedata.getIsoverstandard3())) {
                                                    WqDataBasicevaluatedata.setIsOverStandard(String.valueOf(WqDataBasicevaluatedata.getIsoverstandard3()));
                                                }
                                                if (overStandardTimes3s != null && !"".equals(overStandardTimes3s)) {
                                                    WqDataBasicevaluatedata.setOverStandardDescribe(String.valueOf(overStandardTimes3s));
                                                }
                                            }
                                            if (integer1 == 4) {
                                                if (WqDataBasicevaluatedata.getIsoverstandard4() != null && !"".equals(WqDataBasicevaluatedata.getIsoverstandard4())) {
                                                    WqDataBasicevaluatedata.setIsOverStandard(String.valueOf(WqDataBasicevaluatedata.getIsoverstandard4()));
                                                }
                                                if (overStandardTimes4s != null && !"".equals(overStandardTimes4s)) {
                                                    WqDataBasicevaluatedata.setOverStandardDescribe(String.valueOf(overStandardTimes4s));
                                                }
                                            }
                                            if (integer1 == 5) {
                                                if (WqDataBasicevaluatedata.getIsoverstandard5() != null && !"".equals(WqDataBasicevaluatedata.getIsoverstandard5())) {
                                                    WqDataBasicevaluatedata.setIsOverStandard(String.valueOf(WqDataBasicevaluatedata.getIsoverstandard5()));
                                                }
                                                if (overStandardTimes5s != null && !"".equals(overStandardTimes5s)) {
                                                    WqDataBasicevaluatedata.setOverStandardDescribe(String.valueOf(overStandardTimes5s));
                                                }
                                            }
                                        }
                                        //根据上面数据处理完成进行插入数据
                                        //判断手工数据是否存在
                                        if (getbasicevaluatedata != null && getbasicevaluatedata.size() > 0) {
                                            String bussinesscategorycode = WqDataBasicevaluatedata.getBussinesscategorycode();
                                            String HorizontalAzimuth = WqDataBasicevaluatedata.getHorizontalazimuth();
                                            List<Map<String, Object>> getbasicsmonitordatalist = new ArrayList<>();
                                            if (bussinesscategorycode != null && "CBN3".equals(bussinesscategorycode)) {
                                                getbasicsmonitordatalist = getbasicevaluatedata.stream()
                                                        .filter(item -> String.valueOf(item.get("SegmentID")).equals(String.valueOf(SegmentIDdate))
                                                                && String.valueOf(item.get("BussinessCategoryCode")).equals(String.valueOf(bussinesscategorycode))

                                                                && String.valueOf(item.get("SampleDataTimes")).equals(String.valueOf(dateTime))
                                                                // && item.get("SampleDataTimes").equals(dateTime)
//                                                                && String.valueOf(item.get("HorizontalAzimuth")).equals(String.valueOf(HorizontalAzimuth))
                                                                && String.valueOf(item.get("dataSource")).equals(WqDataBasicevaluatedata.getDatasource())

                                                        )
                                                        .collect(Collectors.toList());
                                            } else {
                                                getbasicsmonitordatalist = getbasicevaluatedata.stream()
                                                        .filter(item -> String.valueOf(item.get("SegmentID")).equals(String.valueOf(SegmentIDdate))
                                                                && String.valueOf(item.get("BussinessCategoryCode")).equals(String.valueOf(bussinesscategorycode))

                                                                && String.valueOf(item.get("SampleDataTimes")).equals(String.valueOf(dateTime))
                                                                // && item.get("SampleDataTimes").equals(dateTime)
//                                                                && String.valueOf(item.get("HorizontalAzimuth")).equals(String.valueOf(HorizontalAzimuth))
                                                                && String.valueOf(item.get("dataSource")).equals(WqDataBasicevaluatedata.getDatasource())
                                                        )
                                                        .collect(Collectors.toList());
                                            }

                                            //如果存在数据就更新对应id的数据
                                            String ids = "";
                                            String isOverStandardses = WqDataBasicevaluatedata.getIsOverStandard();
                                            if (isOverStandardses != null && !"".equals(isOverStandardses)) {

                                            } else {
                                                WqDataBasicevaluatedata.setIsOverStandard("0");
                                            }
                                            if (getbasicsmonitordatalist != null && getbasicsmonitordatalist.size() > 0) {
                                                for (Map<String, Object> getbasicsmonitordatalistdata : getbasicsmonitordatalist) {
                                                    Object idse = getbasicsmonitordatalistdata.get("ID");
                                                    ids = String.valueOf(idse);
                                                }
                                            }
                                            if (ids != null && !"".equals(ids)) {
                                                WqDataBasicevaluatedata.setId(ids);
                                                busBasicevaluatedataMapper.updateWq_data_basicevaluatedata(WqDataBasicevaluatedata);
                                            } else {
                                                busBasicevaluatedataMapper.insertWq_data_basicevaluatedata(WqDataBasicevaluatedata);
                                            }
                                        } else {
                                            busBasicevaluatedataMapper.insertWq_data_basicevaluatedata(WqDataBasicevaluatedata);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        return 0;
    }

    /**
     * 手工数据评价表执行 （综合监测数据）
     *
     * @Param SampleDataTimelist 时间
     * * SegmentIDlist 断面id
     * * minSampleDataTime 开始时间
     * * maxSampleDataTime 结束时间
     **/
    public int getintegrationevaluatedata(String BussinessCategoryCode, List<String> SegmentIDlist, String minSampleDataTime, String maxSampleDataTime) {
        List<Map<String, Object>> hlroundingOffmapsdata = segmentFormula.wqBasStandardcategory(null, null);
        int cgcl = 0;
        //查询对应监测断面数据
        SimpleDateFormat sdfsampleTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //设置时间格式
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM"); //设置时间格式
        Map<String, Object> getbasicsmonitordatadatamap = new HashMap<>();
        Map<String, Object> getbasicevaluatedataamap = new HashMap<>();
        getbasicsmonitordatadatamap.put("SegmentIDs", SegmentIDlist);
        getbasicsmonitordatadatamap.put("ksSampleTimes", minSampleDataTime);
        getbasicsmonitordatadatamap.put("jsSampleTimes", maxSampleDataTime);
        getbasicsmonitordatadatamap.put("BussinessCategoryCode", BussinessCategoryCode);
        getbasicsmonitordatadatamap.put("ItemCode", "1");
        getbasicsmonitordatadatamap.put("IsRiverEvalute", "1");
        if (BussinessCategoryCode != null && "CBF8".equals(BussinessCategoryCode)) {
            getbasicsmonitordatadatamap.put("IsRiverEvalute", "3");
        } else if (BussinessCategoryCode != null && "CBF1".equals(BussinessCategoryCode)) {
            getbasicsmonitordatadatamap.put("IsRiverEvalute", "2");
        }

        List<Map<String, Object>> getbasicsmonitordatadata = busIntegrationevaluatedataMapper.getintegrationmonitordatadatav1(getbasicsmonitordatadatamap);
        Map<String, Object> wqBasItemIDIsRiverEvalutemap = new HashMap<>();
        wqBasItemIDIsRiverEvalutemap.put("IsRiverEvalute", "1");
        if (BussinessCategoryCode != null && "CBF8".equals(BussinessCategoryCode)) {
            wqBasItemIDIsRiverEvalutemap.put("IsRiverEvalute", "3");
        } else if (BussinessCategoryCode != null && "CBF1".equals(BussinessCategoryCode)) {
            wqBasItemIDIsRiverEvalutemap.put("IsRiverEvalute", "2");
        }
        List<String> ItemCategroylist = new ArrayList<>();
        ItemCategroylist.add("0");
        ItemCategroylist.add("1");
        wqBasItemIDIsRiverEvalutemap.put("ItemCategroylist", ItemCategroylist);
        List<Map<String, Object>> wqBasItemIDIsRiverEvalutelist = publicToolsMapper.wqBasItemIDIsRiverEvalute(wqBasItemIDIsRiverEvalutemap);//

//dateTime 根据时间获取前一天小时的时间
        Date ksparse = null;
        Date jsparse = null;
        try {
            ksparse = sdfsampleTime.parse(String.valueOf(minSampleDataTime));
            jsparse = sdfsampleTime.parse(String.valueOf(maxSampleDataTime));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Calendar kscalendar = Calendar.getInstance(); // 获取当前时间的Calendar实例
        kscalendar.setTime(ksparse);
        kscalendar.add(Calendar.MONTH, -1); // 将日期设置为前一天
        Calendar jscalendar = Calendar.getInstance(); // 获取当前时间的Calendar实例
        jscalendar.setTime(jsparse);
        jscalendar.add(Calendar.MONTH, -1); // 将日期设置为前一天
        String ksformat = sdf.format(kscalendar.getTime());
        String jsformat = sdf.format(jscalendar.getTime());
        String jsformats = sdf.format(jsparse);
        getbasicsmonitordatadatamap.put("ksSampleTime", ksformat);
        getbasicsmonitordatadatamap.put("jsSampleTime", jsformat);
        List<Map<String, Object>> hbgetbasicsmonitordatadata = busIntegrationevaluatedataMapper.getintegrationmonitordatahb(getbasicsmonitordatadatamap);
        getbasicsmonitordatadatamap.put("jsSampleTime", jsformats);
        List<Map<String, Object>> getbasicevaluatedata = busIntegrationevaluatedataMapper.getintegrationevaluatedata(getbasicsmonitordatadatamap);
        //获取时间
        List<String> SampleDataTimelist = new ArrayList<>();
        if (getbasicsmonitordatadata != null && getbasicsmonitordatadata.size() > 0) {
            for (Map<String, Object> dataTIme : getbasicsmonitordatadata) {
                Object sampleDatese = dataTIme.get("SampleDate");
                boolean contains = SampleDataTimelist.contains(sampleDatese);
                if (contains) {
                } else {
                    SampleDataTimelist.add(String.valueOf(sampleDatese));
                }
            }
        }


        //根据断面id和时间进行分组处理一个断面一个时间的数据
        if (SampleDataTimelist != null && SampleDataTimelist.size() > 0) {
            for (String dateTime : SampleDataTimelist) {
                //根据断面id进行分组处理一个断面的数据
                if (SegmentIDlist != null && SegmentIDlist.size() > 0) {
                    for (String SegmentIDdate : SegmentIDlist) {
                        List<String> datastring = new ArrayList<>();//所有因子的水质指数集合
                        if (getbasicsmonitordatadata != null && getbasicsmonitordatadata.size() > 0) {
                            List<String> dataSourceList=new ArrayList<>();
                            for(Map<String, Object> dataSourceMap:getbasicsmonitordatadata){
                                if(!dataSourceList.contains(String.valueOf(dataSourceMap.get("dataSource")))){
                                    dataSourceList.add(String.valueOf(dataSourceMap.get("dataSource")));
                                }
                            }

                            for(String dataSource:dataSourceList){
                                List<Map<String, Object>> sunmapsLevel = getbasicsmonitordatadata.stream()
                                        .filter(item -> item.get("ID").equals(SegmentIDdate)
                                                && item.get("SampleDate").equals(dateTime)
                                                && item.get("dataSource").equals(dataSource)
                                        )
                                        .collect(Collectors.toList());
                                //上面根据断面id/时间分组完后的数据进行处理
                                BusIntegrationevaluatedata WqDataIntegrationevaluatedata = new BusIntegrationevaluatedata();
                                //临时字段
                                Integer QualityLevel = 0;
                                String isOverStandard5s = "0";
                                String isOverStandard4s = "0";
                                String isOverStandard3s = "0";
                                String isOverStandard2s = "0";
                                String isOverStandard1s = "0";
                                String overStandardTimes5s = "";
                                String overStandardTimes4s = "";
                                String overStandardTimes3s = "";
                                String overStandardTimes2s = "";
                                String overStandardTimes1s = "";
                                String targetLevelse = "";

                                if (sunmapsLevel != null && sunmapsLevel.size() > 0) {
                                    for (Map<String, Object> data : sunmapsLevel) {
                                        Object id = data.get("ID");//断面id
                                        Object Remark1 = data.get("Remark1");//
                                        if (id != null && !"".equals(id)) {
                                            WqDataIntegrationevaluatedata.setSegmentid(String.valueOf(id));

                                        }
                                        Object segmentName = data.get("SegmentName");//断面名称
                                        if (segmentName != null && !"".equals(segmentName)) {
                                            WqDataIntegrationevaluatedata.setSegmentname(String.valueOf(segmentName));

                                        }
                                        //0河流/1湖库/2地下水
                                        Object segmentCategorys = data.get("segmentCategorys");//断面类型
                                        //0地表水 1地下水
                                        Object segmentCategory = data.get("segmentCategory");
                                        //断面编码
                                        Object segmentCode = data.get("SegmentCode");
                                        if (segmentCode != null && !"".equals(segmentCode)) {
                                            WqDataIntegrationevaluatedata.setSegmentcode(String.valueOf(segmentCode));

                                        }
                                        Object reportID = data.get("ReportID");
                                        if (reportID != null && !"".equals(reportID)) {
                                            WqDataIntegrationevaluatedata.setReportid(String.valueOf(reportID));

                                        }
                                        //数据编码
                                        Object bussinessCategoryCode = data.get("BussinessCategoryCode");
                                        if (bussinessCategoryCode != null && !"".equals(bussinessCategoryCode)) {
                                            WqDataIntegrationevaluatedata.setBussinesscategorycode(String.valueOf(bussinessCategoryCode));
                                        }
                                        //数据名称
                                        Object bussinessCategory = data.get("BussinessCategory");
                                        if (bussinessCategory != null && !"".equals(bussinessCategory)) {
                                            WqDataIntegrationevaluatedata.setBussinesscategory(String.valueOf(bussinessCategory));
                                        }

                                    /*bject remark = data.get("Remark");//备注
                                    if (remark != null && !"".equals(remark)) {
                                        WqDataIntegrationevaluatedata.setRemark(String.valueOf(remark));
                                    }*/
                                        Object orginalValue = data.get("OrginalValue");
                                        Object itemName = data.get("ItemName");//因子名称
                                        Object itemCode = data.get("ItemCode");//因子编码
                                        if (Remark1 != null && !"".equals(Remark1) && "1".equals(Remark1)) {

                                        } else {
                                            //0正常 1超标
                                            Object isOverStandard5 = data.get("IsOverStandard5");//五类是否超标
                                            if (isOverStandard5 != null && !"".equals(isOverStandard5)) {
                                                isOverStandard5s = String.valueOf(isOverStandard5);
                                            }
                                            Object overStandardTimes5 = data.get("OverStandardTimes5");//超标倍数+因子
                                            if (isOverStandard5 != null && !"".equals(isOverStandard5) && "1".equals(isOverStandard5)) {
                                                if (overStandardTimes5s != null && !"".equals(overStandardTimes5s)) {
                                                    overStandardTimes5s = overStandardTimes5s + "," + String.valueOf(itemName);
                                                    if (StringUtils.isNotNull(overStandardTimes5)) {
                                                        overStandardTimes5s = overStandardTimes5s + "(" + overStandardTimes5 + ")";
                                                    }
                                                } else {
                                                    if (StringUtils.isNotNull(overStandardTimes5)) {
                                                        overStandardTimes5s = String.valueOf(itemName) + "(" + overStandardTimes5 + ")";
                                                    } else {
                                                        overStandardTimes5s = String.valueOf(itemName);
                                                    }

                                                }
                                            }
//                                        if (overStandardTimes5 != null && !"".equals(overStandardTimes5)) {
//                                            if (overStandardTimes5s != null && !"".equals(overStandardTimes5s)) {
//                                                overStandardTimes5s = overStandardTimes5s + "," + String.valueOf(overStandardTimes5);
//
//                                            } else {
//                                                overStandardTimes5s = String.valueOf(overStandardTimes5);
//                                            }
//                                        }else if (isOverStandard5 != null && !"".equals(isOverStandard5)&&"1".equals(isOverStandard5)){
//                                            if (overStandardTimes5s != null && !"".equals(overStandardTimes5s)) {
//                                                overStandardTimes5s = overStandardTimes5s + "," + String.valueOf(itemName);
//                                            } else {
//                                                overStandardTimes5s=String.valueOf(itemName);
//                                            }
//                                        }
                                            Object isOverStandard4 = data.get("IsOverStandard4");
                                            if (isOverStandard4 != null && !"".equals(isOverStandard4)) {
                                                isOverStandard4s = String.valueOf(isOverStandard4);
                                            }
                                            Object overStandardTimes4 = data.get("OverStandardTimes4");
                                            if (isOverStandard4 != null && !"".equals(isOverStandard4) && "1".equals(isOverStandard4)) {
                                                if (overStandardTimes4s != null && !"".equals(overStandardTimes4s)) {
                                                    overStandardTimes4s = overStandardTimes4s + "," + String.valueOf(itemName);
                                                    if (StringUtils.isNotNull(overStandardTimes4)) {
                                                        overStandardTimes4s = overStandardTimes4s + "(" + overStandardTimes4 + ")";
                                                    }
                                                } else {
                                                    if (StringUtils.isNotNull(overStandardTimes4)) {
                                                        overStandardTimes4s = String.valueOf(itemName) + "(" + overStandardTimes4 + ")";
                                                    } else {
                                                        overStandardTimes4s = String.valueOf(itemName);
                                                    }

                                                }
                                            }

//                                        if (overStandardTimes4 != null && !"".equals(overStandardTimes4)) {
//                                            if (overStandardTimes4s != null && !"".equals(overStandardTimes4s)) {
//                                                overStandardTimes4s = overStandardTimes4s + "," + String.valueOf(overStandardTimes4);
//                                            } else {
//                                                overStandardTimes4s = String.valueOf(overStandardTimes4);
//                                            }
//                                        }else if (isOverStandard4 != null && !"".equals(isOverStandard4)&&"1".equals(isOverStandard4)){
//                                            //overStandardTimes4s=String.valueOf(itemName);
//                                            if (overStandardTimes4s != null && !"".equals(overStandardTimes4s)) {
//                                                overStandardTimes4s = overStandardTimes4s + "," + String.valueOf(itemName);
//                                            } else {
//                                                overStandardTimes4s=String.valueOf(itemName);
//                                            }
//                                        }
                                            Object isOverStandard3 = data.get("IsOverStandard3");
                                            if (isOverStandard3 != null && !"".equals(isOverStandard3)) {
                                                isOverStandard3s = String.valueOf(isOverStandard3);
                                            }
                                            Object overStandardTimes3 = data.get("OverStandardTimes3");
                                            if (isOverStandard3 != null && !"".equals(isOverStandard3) && "1".equals(isOverStandard3)) {
                                                if (overStandardTimes3s != null && !"".equals(overStandardTimes3s)) {
                                                    overStandardTimes3s = overStandardTimes3s + "," + String.valueOf(itemName);
                                                    if (StringUtils.isNotNull(overStandardTimes3)) {
                                                        overStandardTimes3s = overStandardTimes3s + "(" + overStandardTimes3 + ")";
                                                    }
                                                } else {
                                                    if (StringUtils.isNotNull(overStandardTimes3)) {
                                                        overStandardTimes3s = String.valueOf(itemName) + "(" + overStandardTimes3 + ")";
                                                    } else {
                                                        overStandardTimes3s = String.valueOf(itemName);
                                                    }

                                                }
                                            }

//                                        if (overStandardTimes3 != null && !"".equals(overStandardTimes3)) {
//                                            if (overStandardTimes3s != null && !"".equals(overStandardTimes3s)) {
//                                                overStandardTimes3s = overStandardTimes3s + "," + String.valueOf(overStandardTimes3);
//                                            } else {
//                                                overStandardTimes3s = String.valueOf(overStandardTimes3);
//                                            }
//                                        }else if (isOverStandard3 != null && !"".equals(isOverStandard3)&&"1".equals(isOverStandard3)){
//                                            if (overStandardTimes3s != null && !"".equals(overStandardTimes3s)) {
//                                                overStandardTimes3s = overStandardTimes3s + "," + String.valueOf(itemName);
//                                            } else {
//                                                overStandardTimes3s=String.valueOf(itemName);
//                                            }
//
//                                        }
                                            Object isOverStandard2 = data.get("IsOverStandard2");
                                            if (isOverStandard2 != null && !"".equals(isOverStandard2)) {
                                                isOverStandard2s = String.valueOf(isOverStandard2);
                                            }
                                            Object overStandardTimes2 = data.get("OverStandardTimes2");
                                            if (isOverStandard2 != null && !"".equals(isOverStandard2) && "1".equals(isOverStandard2)) {
                                                if (overStandardTimes2s != null && !"".equals(overStandardTimes2s)) {
                                                    overStandardTimes2s = overStandardTimes2s + "," + String.valueOf(itemName);
                                                    if (StringUtils.isNotNull(overStandardTimes2)) {
                                                        overStandardTimes2s = overStandardTimes2s + "(" + overStandardTimes2 + ")";
                                                    }
                                                } else {
                                                    if (StringUtils.isNotNull(overStandardTimes2)) {
                                                        overStandardTimes2s = String.valueOf(itemName) + "(" + overStandardTimes2 + ")";
                                                    } else {
                                                        overStandardTimes2s = String.valueOf(itemName);
                                                    }

                                                }
                                            }

//                                        if (overStandardTimes2 != null && !"".equals(overStandardTimes2)) {
//                                            if (overStandardTimes2s != null && !"".equals(overStandardTimes2s)) {
//                                                overStandardTimes2s = overStandardTimes2s + "," + String.valueOf(overStandardTimes2);
//                                            } else {
//                                                overStandardTimes2s = String.valueOf(overStandardTimes2);
//                                            }
//                                        }else if (isOverStandard2 != null && !"".equals(isOverStandard2)&&"1".equals(isOverStandard2)){
//                                            // overStandardTimes2s=String.valueOf(itemName);
//                                            if (overStandardTimes2s != null && !"".equals(overStandardTimes2s)) {
//                                                overStandardTimes2s = overStandardTimes2s + "," + String.valueOf(itemName);
//                                            } else {
//                                                overStandardTimes2s=String.valueOf(itemName);
//                                            }
//                                        }
                                            Object isOverStandard1 = data.get("IsOverStandard1");
                                            if (isOverStandard1 != null && !"".equals(isOverStandard1)) {
                                                isOverStandard1s = String.valueOf(isOverStandard1);
                                            }
                                            Object overStandardTimes1 = data.get("OverStandardTimes1");
                                            if (isOverStandard1 != null && !"".equals(isOverStandard1) && "1".equals(isOverStandard1)) {
                                                if (overStandardTimes1s != null && !"".equals(overStandardTimes1s)) {
                                                    overStandardTimes1s = overStandardTimes1s + "," + String.valueOf(itemName);
                                                    if (StringUtils.isNotNull(overStandardTimes1)) {
                                                        overStandardTimes1s = overStandardTimes1s + "(" + overStandardTimes1 + ")";
                                                    }
                                                } else {
                                                    if (StringUtils.isNotNull(overStandardTimes1)) {
                                                        overStandardTimes1s = String.valueOf(itemName) + "(" + overStandardTimes1 + ")";
                                                    } else {
                                                        overStandardTimes1s = String.valueOf(itemName);
                                                    }

                                                }
                                            }

//                                        if (overStandardTimes1 != null && !"".equals(overStandardTimes1)) {
//                                            if (overStandardTimes1s != null && !"".equals(overStandardTimes1s)) {
//                                                overStandardTimes1s = overStandardTimes1s + "," + String.valueOf(overStandardTimes1);
//                                            } else {
//                                                overStandardTimes1s = String.valueOf(overStandardTimes1);
//                                            }
//                                        }else if (isOverStandard1 != null && !"".equals(isOverStandard1)&&"1".equals(isOverStandard1)){
//                                            // overStandardTimes1s=String.valueOf(itemName);
//                                            if (overStandardTimes1s != null && !"".equals(overStandardTimes1s)) {
//                                                overStandardTimes1s = overStandardTimes1s + "," + String.valueOf(itemName);
//                                            } else {
//                                                overStandardTimes1s=String.valueOf(itemName);
//                                            }
//                                        }
                                            Object qualityLevel = data.get("QualityLevel");//水质级别
                                            if (qualityLevel != null && !"".equals(qualityLevel)) {
                                                Integer integer = Integer.valueOf(String.valueOf(qualityLevel));
                                                if (integer > QualityLevel) {
                                                    QualityLevel = integer;
                                                }
                                            }
                                        }


                                        Object sampleDates = data.get("SampleDates");//时间 未格式

                                        Object sampleDatese = data.get("SampleDatese");//时间 格式化不变时间
                                        Object sampleDate = data.get("SampleDate");//时间 格式化 时分秒 未0
                                        if (sampleDate != null && !"".equals(sampleDate)) {
                                            Date parse = null;
                                            try {
                                                parse = sdfsampleTime.parse(String.valueOf(sampleDate));
                                            } catch (ParseException e) {
                                                e.printStackTrace();
                                            }
                                            WqDataIntegrationevaluatedata.setSampledate(parse);
                                        }
                                        Object targetLevel = data.get("TargetLevel");
                                        Object targetLevelName = data.get("TargetLevelName");
                                        if (targetLevel != null && !"".equals(targetLevel)) {
                                            Integer integer = Integer.valueOf(String.valueOf(targetLevel));
                                            targetLevelse = String.valueOf(integer);
                                            WqDataIntegrationevaluatedata.setTargetLevel(integer);
                                        }
                                        if (targetLevelName != null && !"".equals(targetLevelName)) {
                                            WqDataIntegrationevaluatedata.setTargetLevelName(String.valueOf(targetLevelName));
                                        }
                                        if (segmentCategorys != null && !"".equals(segmentCategorys)) {
                                            WqDataIntegrationevaluatedata.setSegmentCategory(String.valueOf(segmentCategorys));
                                        }

                                        Object EffectiveValue = data.get("EffectiveValue");//监测均值
                                        Object segmentCategoryS = data.get("segmentCategorys");//监测均值
                                        //判断是否科学计算法，如果是就进行转换
                                        if (EffectiveValue != null && !"".equals(EffectiveValue) && Double.valueOf(String.valueOf(EffectiveValue)) > 0) {
                                            boolean scientificNotation = StringUtils.isScientificNotation(String.valueOf(EffectiveValue));
                                            if (scientificNotation) {
                                                BigDecimal bigDecimal = new BigDecimal(String.valueOf(EffectiveValue));
                                                String effectiveValuesdatas = bigDecimal.toPlainString();
                                                EffectiveValue = effectiveValuesdatas;
                                            } else {
                                                EffectiveValue = String.valueOf(EffectiveValue);
                                            }
                                            if (wqBasItemIDIsRiverEvalutelist != null && wqBasItemIDIsRiverEvalutelist.size() > 0) {
                                                List<Map<String, Object>> wqBasItemIDIsRiverEvalute = wqBasItemIDIsRiverEvalutelist.stream()
                                                        .filter(item -> item.get("ID").equals(itemCode)
                                                        )
                                                        .collect(Collectors.toList());
                                                if (wqBasItemIDIsRiverEvalute != null && wqBasItemIDIsRiverEvalute.size() > 0) {
                                                    //水质指数计算
                                                    //调用工具返回对应指数计算后的值 // _IN 指数 _V 均值
                                                    if (itemName != null && !"".equals(itemName)) {
                                                        //获取修约的标准值
                                                        String roundingOffstandardValue = "0";
                                                        //获取计算水质指数的标准值
                                                        String indexstandardValue = "0";
                                                        //分组查询
                                                        if (hlroundingOffmapsdata != null && hlroundingOffmapsdata.size() > 0) {
                                                            //WaterType Level
                                                            List<Map<String, Object>> roundingOffmaps = hlroundingOffmapsdata.stream()
                                                                    .filter(item -> item.get("WaterType").equals(String.valueOf(segmentCategoryS))
                                                                            && item.get("Level").equals("1")
                                                                    )
                                                                    .collect(Collectors.toList());
                                                            List<Map<String, Object>> indexmaps = hlroundingOffmapsdata.stream()
                                                                    .filter(item -> item.get("WaterType").equals(String.valueOf(segmentCategoryS))
                                                                            && item.get("Level").equals("3")
                                                                    )
                                                                    .collect(Collectors.toList());
                                                            if (roundingOffmaps != null && roundingOffmaps.size() > 0) {
                                                                for (Map<String, Object> datas : roundingOffmaps) {
                                                                    Object standardValue = datas.get("StandardValue");//标准值
                                                                    Object itemCodedata = datas.get("ItemCode");//因子编码
                                                                    if (itemCode != null && !"".equals(itemCode) && itemCodedata.equals(itemCode)) {
                                                                        roundingOffstandardValue = String.valueOf(standardValue);
                                                                    }
                                                                }
                                                            }


                                                            if (indexmaps != null && indexmaps.size() > 0) {
                                                                for (Map<String, Object> datas : indexmaps) {
                                                                    Object standardValue = datas.get("StandardValue");//标准值
                                                                    Object itemCodedata = datas.get("ItemCode");//因子编码
                                                                    if (itemCode != null && !"".equals(itemCode) && itemCodedata.equals(itemCode)) {
                                                                        indexstandardValue = String.valueOf(standardValue);
                                                                    }
                                                                }
                                                            }


                                                        }
                                                        if (bussinessCategoryCode != null && !"CBF1".equals(bussinessCategoryCode) && !"CBF8".equals(bussinessCategoryCode)) {
                                                            //itemName 监测值名称, type 断面类型, beginTime 开始时间, endTime 结束时间, itemdata 监测值
                                                            // indexstandardLimits 计算水质指数的标准值  roundingOffstandardLimits 计算均值修约的数据 itemName 监测值名称, type 断面类型, beginTime 开始时间, endTime 结束时间, itemdata 监测值]
                                                            Map maplistData = segmentFormula.itemDataINV(indexstandardValue, roundingOffstandardValue, String.valueOf(itemCode), String.valueOf(itemName), String.valueOf(segmentCategoryS), "", "", String.valueOf(EffectiveValue));
                                                            if (maplistData != null && maplistData.size() > 0) {
                                                                Object v = maplistData.get("_V"); //修约后的值
                                                                Object in = maplistData.get("_IN");//单个因子的指数
                                                                Object itemCodeData = maplistData.get("itemCode");//因子编码/id
                                                                maplistData.put(itemCode + "_IN", in);//水质指数
                                                                if (in != null && !"".equals(in)) {
                                                                    datastring.add(String.valueOf(in));
                                                                }
                                                            }
                                                        }

                                                    }
                                                }


                                            }

                                        }

                                    }

                                    //调用完工具类后所有水质指数进行相加总和数据
                                    if (datastring != null && datastring.size() > 0) {
                                        String dataValue = segmentFormula.riverWaterQualityIndex(datastring);
                                        WqDataIntegrationevaluatedata.setSegmentIndex(dataValue);
                                    }
                                    if (overStandardTimes1s != null && !"".equals(overStandardTimes1s)) {
                                        WqDataIntegrationevaluatedata.setIsoverstandard1("1");
                                    } else {
                                        WqDataIntegrationevaluatedata.setIsoverstandard1(isOverStandard1s);
                                    }
                                    if (overStandardTimes2s != null && !"".equals(overStandardTimes2s)) {
                                        WqDataIntegrationevaluatedata.setIsoverstandard2("1");
                                    } else {
                                        WqDataIntegrationevaluatedata.setIsoverstandard2(isOverStandard2s);
                                    }
                                    if (overStandardTimes3s != null && !"".equals(overStandardTimes3s)) {
                                        WqDataIntegrationevaluatedata.setIsoverstandard3("1");
                                    } else {
                                        WqDataIntegrationevaluatedata.setIsoverstandard3(isOverStandard3s);
                                    }
                                    if (overStandardTimes4s != null && !"".equals(overStandardTimes4s)) {
                                        WqDataIntegrationevaluatedata.setIsoverstandard4("1");
                                    } else {
                                        WqDataIntegrationevaluatedata.setIsoverstandard4(isOverStandard4s);
                                    }
                                    if (overStandardTimes5s != null && !"".equals(overStandardTimes5s)) {
                                        WqDataIntegrationevaluatedata.setIsoverstandard5("1");
                                    } else {
                                        WqDataIntegrationevaluatedata.setIsoverstandard5(isOverStandard5s);
                                    }
                                /*WqDataIntegrationevaluatedata.setIsoverstandard1(isOverStandard1s);
                                WqDataIntegrationevaluatedata.setIsoverstandard2(isOverStandard2s);
                                WqDataIntegrationevaluatedata.setIsoverstandard3(isOverStandard3s);
                                WqDataIntegrationevaluatedata.setIsoverstandard4(isOverStandard4s);
                                WqDataIntegrationevaluatedata.setIsoverstandard5(isOverStandard5s);*/
                                    WqDataIntegrationevaluatedata.setOverstandarddescribe1(overStandardTimes1s);
                                    WqDataIntegrationevaluatedata.setOverstandarddescribe2(overStandardTimes2s);
                                    WqDataIntegrationevaluatedata.setOverstandarddescribe3(overStandardTimes3s);
                                    WqDataIntegrationevaluatedata.setOverstandarddescribe4(overStandardTimes4s);
                                    WqDataIntegrationevaluatedata.setOverstandarddescribe5(overStandardTimes5s);
                                    if (QualityLevel != null && !"".equals(QualityLevel)) {
                                        WqDataIntegrationevaluatedata.setQualitylevel(QualityLevel);
                                        //转换水质级别名称
                                        String LevelName = WaterLevelCompute.GetLevelName(QualityLevel, "无类别");
                                        WqDataIntegrationevaluatedata.setQualitylevelname(LevelName);
                                        //水质评价结果
                                        Map<String, Object> stringObjectMap = segmentFormula.waterQuality(QualityLevel);
                                        if (stringObjectMap != null && stringObjectMap.size() > 0) {
                                            Object waterQuality = stringObjectMap.get("waterQuality");
                                            WqDataIntegrationevaluatedata.setWaterQuality(String.valueOf(waterQuality));
                                        }
                                    }
                                    if (targetLevelse != null && !"".equals(targetLevelse)) {
                                        Integer integer1 = Integer.valueOf(targetLevelse);
                                        if (integer1 == 1) {
                                            if (WqDataIntegrationevaluatedata.getIsoverstandard1() != null && !"".equals(WqDataIntegrationevaluatedata.getIsoverstandard1())) {
                                                WqDataIntegrationevaluatedata.setIsOverStandard(String.valueOf(WqDataIntegrationevaluatedata.getIsoverstandard1()));
                                            }
                                            if (overStandardTimes1s != null && !"".equals(overStandardTimes1s)) {
                                                WqDataIntegrationevaluatedata.setOverStandardDescribe(String.valueOf(overStandardTimes1s));
                                            }
                                        }
                                        if (integer1 == 2) {
                                            if (WqDataIntegrationevaluatedata.getIsoverstandard2() != null && !"".equals(WqDataIntegrationevaluatedata.getIsoverstandard2())) {
                                                WqDataIntegrationevaluatedata.setIsOverStandard(String.valueOf(WqDataIntegrationevaluatedata.getIsoverstandard2()));
                                            }
                                            if (overStandardTimes2s != null && !"".equals(overStandardTimes2s)) {
                                                WqDataIntegrationevaluatedata.setOverStandardDescribe(String.valueOf(overStandardTimes2s));
                                            }
                                        }
                                        if (integer1 == 3) {
                                            if (WqDataIntegrationevaluatedata.getIsoverstandard3() != null && !"".equals(WqDataIntegrationevaluatedata.getIsoverstandard3())) {
                                                WqDataIntegrationevaluatedata.setIsOverStandard(String.valueOf(WqDataIntegrationevaluatedata.getIsoverstandard3()));
                                            }
                                            if (overStandardTimes3s != null && !"".equals(overStandardTimes3s)) {
                                                WqDataIntegrationevaluatedata.setOverStandardDescribe(String.valueOf(overStandardTimes3s));
                                            }
                                        }
                                        if (integer1 == 4) {
                                            if (WqDataIntegrationevaluatedata.getIsoverstandard4() != null && !"".equals(WqDataIntegrationevaluatedata.getIsoverstandard4())) {
                                                WqDataIntegrationevaluatedata.setIsOverStandard(String.valueOf(WqDataIntegrationevaluatedata.getIsoverstandard4()));
                                            }
                                            if (overStandardTimes4s != null && !"".equals(overStandardTimes4s)) {
                                                WqDataIntegrationevaluatedata.setOverStandardDescribe(String.valueOf(overStandardTimes4s));
                                            }
                                        }
                                        if (integer1 == 5) {
                                            if (WqDataIntegrationevaluatedata.getIsoverstandard5() != null && !"".equals(WqDataIntegrationevaluatedata.getIsoverstandard5())) {
                                                WqDataIntegrationevaluatedata.setIsOverStandard(String.valueOf(WqDataIntegrationevaluatedata.getIsoverstandard5()));
                                            }
                                            if (overStandardTimes5s != null && !"".equals(overStandardTimes5s)) {
                                                WqDataIntegrationevaluatedata.setOverStandardDescribe(String.valueOf(overStandardTimes5s));
                                            }
                                        }
                                    }
                                    //水质趋势评价
                                    //获取前一天的水质等级，然后跟当天的比较
                                    Integer lastQualitylevel = 0;
                                    //dateTime 根据时间获取前一天小时的时间
                                    Date parse = null;
                                    try {
                                        parse = sdfsampleTime.parse(String.valueOf(dateTime));
                                    } catch (ParseException e) {
                                        e.printStackTrace();
                                    }
                                    Calendar calendar = Calendar.getInstance(); // 获取当前时间的Calendar实例
                                    calendar.setTime(parse);
                                    calendar.add(Calendar.MONTH, -1); // 将日期设置为前一天
                                    String format = sdf.format(calendar.getTime());
                                    if (hbgetbasicsmonitordatadata != null && hbgetbasicsmonitordatadata.size() > 0) {
                                        List<Map<String, Object>> SampleDatesunmapsLevel = hbgetbasicsmonitordatadata.stream()
                                                .filter(item -> item.get("SampleDatemon").equals(format + "-01 00:00:00")
                                                        && item.get("SegmentID").equals(SegmentIDdate)
                                                )
                                                .collect(Collectors.toList());
                                        if (SampleDatesunmapsLevel != null && SampleDatesunmapsLevel.size() > 0) {
                                            for (Map<String, Object> datasunmapsLevel : SampleDatesunmapsLevel) {
                                                Object qualityLevel = datasunmapsLevel.get("QualityLevel");
                                                if (qualityLevel != null && !"".equals(qualityLevel)) {
                                                    Integer integer = Integer.valueOf(String.valueOf(qualityLevel));
                                                    if (integer > lastQualitylevel) {
                                                        lastQualitylevel = integer;
                                                    }

                                                }
                                            }
                                        }
                                    }

                                    Map<String, Object> evaluationTrend = segmentFormula.evaluationTrend(QualityLevel, lastQualitylevel);
                                    if (evaluationTrend != null && evaluationTrend.size() > 0) {
                                        Object evaluationTrendCode = evaluationTrend.get("evaluationTrendCode");
                                        Object evaluationTrend1 = evaluationTrend.get("evaluationTrend");
                                        WqDataIntegrationevaluatedata.setEvaluationTrend(String.valueOf(evaluationTrend1));
                                        WqDataIntegrationevaluatedata.setEvaluationTrendCode(String.valueOf(evaluationTrendCode));
                                    }
                                    if(StringUtils.isNotNull(dataSource)){
                                        WqDataIntegrationevaluatedata.setDatasource(String.valueOf(dataSource));
                                    }else{
                                        WqDataIntegrationevaluatedata.setDatasource("");
                                    }

                                    //根据上面数据处理完成进行插入数据
                                    //判断手工数据是否存在
                                    if (getbasicevaluatedata != null && getbasicevaluatedata.size() > 0) {
                                        List<Map<String, Object>> getbasicsmonitordatalist = getbasicevaluatedata.stream()
                                                .filter(item -> item.get("SegmentID").equals(SegmentIDdate)
                                                        && item.get("BussinessCategoryCode").equals(WqDataIntegrationevaluatedata.getBussinesscategorycode())
                                                        && item.get("SampleDatse").equals(dateTime)
                                                        && item.get("datasource").equals(WqDataIntegrationevaluatedata.getDatasource())
                                                )
                                                .collect(Collectors.toList());
                                        //如果存在数据就更新对应id的数据
                                        String ids = "";
                                        String isOverStandardses = WqDataIntegrationevaluatedata.getIsOverStandard();
                                        if (isOverStandardses != null && !"".equals(isOverStandardses)) {

                                        } else {
                                            WqDataIntegrationevaluatedata.setIsOverStandard("0");
                                        }
                                        if (getbasicsmonitordatalist != null && getbasicsmonitordatalist.size() > 0) {
                                            for (Map<String, Object> getbasicsmonitordatalistdata : getbasicsmonitordatalist) {
                                                Object idse = getbasicsmonitordatalistdata.get("ID");
                                                ids = String.valueOf(idse);
                                            }
                                        }
                                        if (ids != null && !"".equals(ids)) {
                                            WqDataIntegrationevaluatedata.setId(ids);
                                            int i = busIntegrationevaluatedataMapper.updateWq_data_integrationevaluatedata(WqDataIntegrationevaluatedata);
                                            if (i > 0) {
                                                cgcl++;
                                            }
                                        } else {
                                            int i = busIntegrationevaluatedataMapper.insertWq_data_integrationevaluatedata(WqDataIntegrationevaluatedata);
                                            if (i > 0) {
                                                cgcl++;
                                            }
                                        }

                                    } else {
                                        int i = busIntegrationevaluatedataMapper.insertWq_data_integrationevaluatedata(WqDataIntegrationevaluatedata);
                                        if (i > 0) {
                                            cgcl++;
                                        }
                                    }

                                }
                            }
                        }
                    }
                }
            }
        }


        return cgcl;
    }

}
